System
This namespace contains many commonly-used types. These are separate from the language-level aliases in the C# language.
System
System
is usually specified with a using System
directive. It is included in a default C# file in Visual Studio, but it is worth understanding why it is there.
We look at 3 representations of the same program. The programs have the same output, and should compile to the same intermediate representation.
System.Console
type—it omits the "using System
" directive. It also uses the int
alias in the C# language.int
alias to the System.Int32
type found in the System
alias. The C# language automatically does this.System
" directive at the top. Now, the Console
type can be accessed directly.Int32
can be accessed directly because it too is located in System
. Many other common types require System
.// Version 1. class Program { static void Main() { System.Console.WriteLine(int.Parse("1") + 1); } }// Version 2. class Program { static void Main() { System.Console.WriteLine(System.Int32.Parse("1") + 1); } }// Version 3. using System; class Program { static void Main() { Console.WriteLine(Int32.Parse("1") + 1); } }2
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.
The C# language uses aliased keywords that map to types. For example, if you use the keyword int
, you are using System.Int32
.
int
" is at the language level, you do not need to include System
to use it.System.IO
to get the input-output namespace as well. This can fix compile-time errors.System
can be understood as a commonly-used subset of framework types. It includes types that are mapped to by the aliased keywords in the C# language such as int
.