Main () method, main method
Main
The method is the entry point of the C # console application or window application. (Databases and services do not requireMain
Method as the entry point .) When the application is started,Main
The method is the first method to be called.
C # The program can have only one entry point. If multiple classes containMain
You must use the/main compiler option to compile the program to specifyMain
Method.
1 class MyClass2 {3 static void Main (string [] args) 4 {5 // display the parameter Length of the command line 6 WriteLine (args. Length); 7} 8}
Overview
Main
The method is the entry point of the. exe program, where the program control flow starts and ends.
Main
Declare in a class or structure.Main
It must be static and should not be public. (In the previous example, it accepts the default access level private .) However, the closed class or structure is not required to be static.
Main
There are two types of responses:void
Orint
.
DeclaredMain
The method can contain real arguments of the command line.string[]
Parameter. When using Visual Studio to create a Windows form application, you can manually add the form parameter or use the Environment class to obtain the real arguments of the command line. Command line parameters for reading zero indexes. Different from C and C ++, the program name is regarded as the first command line parameter.