using Directives and Namespaces
The first lines in the code editor contain using directives listing several .Net Framework namespaces. A namespace is a way of grouping classes ad structs together in a way that limits their scope and avoids name conflicts with other classes and structs. When you create a program in Visual C# Express, a namespace is automatically created for u. To use classes from other namespaces in your program, you must specify them with a using Directive. The most commonly used .Net Fraework namespaces are listed by default when you create a new application. If you use classes from other namespaces in the class library, you must add a using directive for that namespace to the source file.
Comments
Comments are useful for including notes to yourself or other programmers.
The characters // convert the rest of the line to a comment. You can also comment a block of text by placing it between the characters /* and */.
Classes
The C# language uses classes to package code: all executable C# code must be contained in a class.
Main()
The C# program must contain a Main method, in whic hcontrol starts and ends. The Main method is where you create objects and execute other methods. The Main method is a static method that resides inside a class or a struct.
Console Input and Output
C# console programs generally use the input/output services provided by .Net Framework Console class.
The WriteLine method displays its string parameter on the commad-line window followed by a new line. The WriteLie method is very useful, and you will use it a lot if you are writing console applications.
WriteLine can display strings:
Console.WriteLine("Hellow World!");
WriteLine can also dispaly numbers:
int x = 42;
Console.WriteLine(x);
If you need to display several items, use {0} to represent the first item, {1} the second item, and so on, like this:
int year = 1066;
string battle = "Battle of Hastings";
Console.WriteLine("The {0} took place in {1}.", battle, year);