Introducing C# and the .NET Framework - Analyzing the Code
(Page 12 of 12 )
Now let's analyze the code that we have written in our "Hello World" example.
1- using System;
This line simply tell the C# compiler to use the classes that live inside the namespace System, so instead of writing fully qualified names like System.Console.WriteLine() we can write Console.WriteLine(). All C# programs use the System namespace because it contains basic functionality such as writing to the console and, as we said before, it contains the basic data types of many other basic structures that are needed by every C# program.
2- namespace FirstApplication{}
This is a namespace declaration that we will define our class within.
3- class Class1{}
This is a C# class declaration. Classes in C# are mobile code; in other words, when you define a class in C# you define all the members in the same class file.
4- static void Main()
This is the definition for the Main() method, which is the entry point of Console-based or Windows-based C# applications. Note that VS.NET generates another version of the Main method, but I don't want to go into the details in these article. For now it is enough to say that the Main method must be static, which means that you don't have to instantiate an object of the class in order to call the method.
Inside the Main method we call the static method WriteLine of the class Console which takes as a paramter a character string to write it to the console.
Note: We used the using System; statement so we can write the statement Console.WriteLine() instead of System.Console.WriteLine.
I hope you've found this article helpful in understanding C# and the .NET Framework.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |