Hello world
The “Hello, World” program is traditionally used to introduce a programming language. Here it is in C#: using System; class Hello C# source files typically have the file extension.cs. Assuming that the “Hello, World” program is stored in the file hello.cs, the program can be compiled with the Microsoft C# compiler using the command line csc hello.cs which produces an executable assembly named hello.exe. The output produced by this application when it is run is Hello, World The “Hello, World” program starts with a using directive that references the System namespace. Namespaces provide a hierarchical means of organizing C# programs and libraries. Namespaces contain types and other namespaces—for example, the System namespace contains a number of types, such as the Console class referenced in the program, and a number of other namespaces, such as IO and Collections. A using directive that references a given namespace enables unqualified use of the types that are members of that namespace. Because of the using directive, the program can use Console.WriteLine as shorthand for System.Console.WriteLine. The Hello class declared by the “Hello, World” program has a single member, the method named Main. The Main method is declared with the static modifier. While instance methods can reference a particular enclosing object instance using the keyword this, static methods operate without reference to a particular object. By convention, a static method named Main serves as the entry point of a program. The output of the program is produced by the WriteLine method of the Console class in the System namespace. This class is provided by the.NET Framework class libraries, which, by default, are automatically referenced by the Microsoft C# compiler. Note that C# itself does not have a separate runtime library. Instead, the.NET Framework is the runtime library of C#.
|