I. Hello World ConsoleProgramSource code
Using system; using system. collections. generic; using system. LINQ; using system. text; namespace helloworld {class program {static void main (string [] ARGs) {// output Hello World console. writeline ("Hello world! "); // Console. writeline (ARGs. Length); // console. Readline ();}}}
Ii. Hello WorldCodeAnalysis
1. Main
The main method is the entry point of the program, and the main is a static method residing in the class or structure, in which other methods are created and called. A c # console application can have only one main method.
Pay attention to the following points when declaring the main method:
(1) The main method is the entry point of the program, and the program control starts and ends in the method;
(2) The main method is declared inside the class or structure and must be a static method;
(3) The main method can have the void or Int return type;
Static VoidMain (String[] ARGs)
{
//...
}
Or
Static IntMain (String[] ARGs)
{
//...
Return 0;
}
(4) When declaring the main method, either parameters or parameters can be used;
(5) parameters can be read as command line parameters starting from 0.
2. Static
Use the static modifier to declare a type, rather than a static member of a specific object. Static modifiers can be used for classes, fields, methods, attributes, operators, events, and constructors, but cannot be used for indexers, destructor, or types other than classes (such as structures ).
(1) Static members cannot be referenced through instances and must be applied by type names;
(2) Instances of all classes share a copy of static fields;
(3) constants or type declarations are implicitly static members;
(4) You cannot use this to reference static methods or attribute accessors;
(5) All members of the static class must be static;
(6) A Class (including a static class) can have a static constructor that calls a static constructor at a certain time between the start of the program and the instantiation class.
3. Hello World source code
Helloworld