66 951
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #15396 in C# for james neece

Question #15396
If you use "using System; why do you need to use another line that says using System.anything?
Expert's answer
System contains many commonly-used types. These are separate from the language-level aliases in the C# language. System can be referenced with
different syntax forms. It is usually specified with a using System
directive.
System

Here we look at three different representations of the same program. The first version uses the System.Console type but does not
add the 'using System' directive. It also uses the int alias in the C#
language.
Version 1 [C#]

class Program
{
static void Main()
{
System.Console.WriteLine(int.Parse("1") + 1);
}
}

Version 2 [C#]

class Program
{
static void Main()
{
System.Console.WriteLine(System.Int32.Parse("1") + 1);
}
}

Version 3 [C#]

using System;

class Program
{
static void Main()
{
Console.WriteLine(Int32.Parse("1") + 1);
}
}

Output

2

The second version changes the 'int' alias to the 'System.Int32' type found in the System alias. The C# language
actually does this for you automatically. It is typically best to use the 'int'
keyword for readability.

The third version adds the 'using System' directive at the top. Now, the Console type can be accessed directly. Also,
Int32 can be accessed directly because it too is located in
System.

Tip:
You can fix several common errors by adding the System namespace to your program. If there are any calls to Console.WriteLine, the
System namespace is required. Many other common functions require System as
well.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions