Getting Started

I l @ ve RuBoard

In keeping with programming tradition, Listing D.1 outlines our first program: "Hello, world".

Listing D.1 The classic "Hello, world" program, hello.cs.
 using System; class Hello {         static void Main() {             // write "Hello, world!" to the screen             Console.WriteLine("Hello, world!");         } } 

Developers with experience in ASP/VBScript should note that the C# language is case sensitive and requires a semicolon at the end of statements like JavaScript. By following convention, we save the source code for our program with a .cs file extension, hello.cs . We can compile our program using the .NET command-line compiler, csc.exe , using the following syntax:

 csc hello.cs 

The output of this directive produces our executable program, hello.exe . The output of the program is as follows :

  Hello, world! 

From this basic example, we can glean several important points:

  • The entry point of a C# program is a static method named Main .

  • As mentioned before, C# does not include a class library. We are able to write to the console using the System.Console class found in the .NET platform framework classes.

  • C, C++, and Java developers may notice that Main is not a global method. This is because C# does not support global methods and variables . These elements must be enclosed within a type declaration such as classes and structs.

  • The Using statement symbolically handles library dependencies instead of importing source with the #include statement found in C and C++.

I l @ ve RuBoard

Asp. Net. By Example
ASP.NET by Example
ISBN: 0789725622
EAN: 2147483647
Year: 2001
Pages: 154

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: