TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C# Using System

This C# article describes the System namespace. It provides an example of System.

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.

Example. We look at three different representations of the same program. The first version uses the System.Console type—it omits the "using System" directive. It also uses the int alias in the C# language.

ConsoleInt

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 automatically does this. 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.

And: If there are any calls to Console.WriteLine, the System namespace is required. Many other common functions require System as well.

Discussion. The C# language uses aliased keywords that map to types. For example, if you use the keyword int, you are actually using System.Int32. However, because "int" is at the language level, you do not need to include System to use it.

Further, there are many namespaces in the .NET Framework, such as System.IO, that are sub-namespaces to System. These are not automatically included with System. You must include System.IO to get the input-output namespace as well.

Tip: Another root namespace available in Visual Studio is the Microsoft namespace.

And: This contains some useful types, such as those required to do Microsoft Office interoperation.

Excel

Summary. System can be understood as a commonly-used subset of the types in the .NET Framework. It is not part of the C# language exactly, but rather it includes types that are mapped to by the aliased keywords in the C# language such as 'int'.


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf