3. 2 main() and command line parameters
The main method is the entry point for the program, where you will create objects and call other methods。
Only one entry point can be found in a c# program, and the main method is the entry point for the program, in which the program controls start and end. Internal statements of the methodology in categories or structures. Note that it must be static, not public. It can have void (no parameters for return) or int (integer type of return). The main method can be declared using both parameters and without them. Parameters can be read as command line parameters for indexing from scratch。
3. 2. 1 application of command line parameters
The main method can use parameters, in which case it takes one of the following forms:
Static int main(string[] args) or static void main(string[] args)
The parameters of the main method are the string arrays that represent the command line parameters. The existence of parameters is usually checked by testing the length properties, such as:
If (args. Length = 2) other organiser system. Console. Writeline. Return 1; ♪ i'm sorry ♪
You can also convert string parameters to numerical types using the convert class or parse method. For example, the following statement converts a string to a long number using parse in category int64:
Long num = int64. Parse (args [2]);
You can also use c#typelong, alias int64:
Long num = long. Parse (args [4]);
Toint64 can also be used to do the same work using the cornvert method:
=convert. Toint64(s);
The parameters provided to the enforceable documents by the command line can be accessed through the optional parameters of main. Parameters are provided in string arrays. Each element of the array contains a parameter. The blank between parameters is removed. For example, the following is an order line for a hypothetical enforceable document。
Function statement: shows the command line parameters passed to the command line application。
List of procedures 3-2
It's not like you're in trouble. Other organiser static void main (stringing] args) other organiser system. Console. Writeline. For (int i = 0; i)The results are shown in figure 3-1。
Figure 3-1 shows the parameters of the command line passed to the application
3. 2. 2 use foreach access line parameters
Another method of circular access to arrays is the use of aforeach statement, as illustrated by the examples below. Foreach statements can be used to loop access arrays, . Net fRamework aggregation class or any category or structure that achieves an ienumerable interface。
Functional description: using a foreach statement, the command line parameters transmitted to the command line application are shown in a circular loop。
List of procedures 3 - 3
Well, well, well. Other organiser static void main (stringing] args) other organiser system. Console. Writeline other organiser foreach (stringing s in arms) other organiser system. Console. Writeline(s); ♪ i'm sorry ♪ ♪ i'm sorry ♪ ♪ i'm sorry ♪The results are shown in figures 3-2。
Figure 3-2 use foreeach access line parameters
3. 2. 3 main() return value identification
The main method may be int type, and if the return value of main is not required, return void can make the code slightly simpler。
The main approach in the following examples can be a void type:
Static void main other organiser / enter code here, no return value ♪ i'm sorry ♪The main approach in the following examples can be of int type:
It's not like you're in the wrong place. Other organiser static int main() other organiser / enter code turn 0; ♪ i'm sorry ♪ ♪ i'm sorry ♪






