TheDeveloperBlog.com

Home | Contact Us

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

<< Back to C-SHARP

C# System (using System namespace)

Understand the System namespace and when it is needed. See example of using 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.
Notes, 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.Namespace
An example. We look at 3 representations of the same program. The programs have the same output, and should compile to the same intermediate representation.

Version 1: The first uses the System.Console type—it omits the "using System" directive. It also uses the int alias in the C# language.

Int, uint

Version 2: This version changes the int alias to the System.Int32 type found in the System alias. The C# language automatically does this.

Version 3: This 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. Many other common types require System.

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
Notes, errors. 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.
Discussion. The C# language uses aliased keywords that map to types. For example, if you use the keyword int, you are using System.Int32.

However: Because "int" is at the language level, you do not need to include System to use it.

Discussion, continued. 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.

Tip: You must include System.IO to get the input-output namespace as well. This can fix compile-time errors.

Microsoft: 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.

A summary. 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.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


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