C # Hello World example

A C # program includes the following components: 
namespace declaration (Namespace declaration) 
a class 
Class methods 
Class attribute 
a Main method 
statement (Statements) & Expressions (Expressions) 
Comment 
Let's look at a can print out "Hello World" of simple code : 
the using the System; 
namespace HelloWorldApplication 

class the HelloWorld 

static void the Main (String [] args) 

/ * my first C # program * / 
Console.WriteLine ( "the Hello World"); 
the Console.ReadKey (); 



when the above code is compiled and executed, it produces the following results: 
the Hello World 
let's look at the various parts of the above program: 
the first line of the program using System; - using the keywords used to include the System namespace in the program. Using a procedure generally have multiple statements. 
The next line is a namespace declaration. A namespace is a series of classes. HelloWorldApplication namespace contains classes HelloWorld. 
The next line is the class declaration. HelloWorld class contains the data used by the program and method declarations. The method generally comprises a plurality of categories. Methods define the behavior of the class. Here, HelloWorld class has only one Main method. 
The next line defines the Main method is the entry point for all C # programs. Main method Description When performing class will do what action. 
The next line / ... / will be ignored by the compiler, and it will add extra comments in the program. 
Main method statement Console.WriteLine ( "Hello World"); specifies its behavior. 
Console WriteLine is a method of a class in the System namespace definition. This statement displays the message "Hello, World!" On the screen. 
The last line Console.ReadKey (); VS.NET is for the user. This action makes the program will wait for a key, the screen will quickly run off and prevent the program from start Visual Studio .NET. 
The following points are noteworthy: 
C # is case-sensitive. 
All statements and expressions must be a semicolon (;) at the end. 
Execution of the program begins with the Main method. 
Unlike Java, the file name can be different from the name of the class. Surrogacy search prestige 13802269370

Guess you like

Origin www.cnblogs.com/qwer24q/p/11857476.html