Role and interpretation of static void Main (string[] args) in C #
Static means that the method is statically, which means that the method is allocated memory when the program is compiled, and does not need to generate a type of object when it is used, knowing that the program exits before it is released.
Void means that the method has no return value, that is, the method has no Renturn keyword.
Main is the method name, of course this method is a special method. is main () is the main function. Is the entry of the entire program, and the program is compiled and started from here. This is also the reason why the main method is static, because the function has to exist when nothing is done.
String[] args means that the command line is an array of strings, that is, the number of references you enter in the command line (the black box) enables multiple strings (meaning that anything can be a command-line parameter in a way).
Execution will pop up the command form, where you can enter some of the parameters, string[] args refers to the number of references you enter in the command form. Args is used to handle command-line parameters. command-line parameters. is the number of references that you pass to the program when you execute it.
It is optional, not required.
How do I pass a parameter to the C # main function? We see the C # main function with a string[] args parameter, so do you know what the actual function is? Let's talk about it in detail below:
Under C # console applications, we often see the main function with a string[] args parameter. So you know what it's for?
Step 1: Build a console application, named Main.cs
Step 2: Paste the following code.
Using System;
Class program{
static void Main (string[] args) {
int argslength = args. Length;
Console.WriteLine ("main function parameter args length:" + argslength.tostring ());
for (int i = 0; i < argslength; i++)
{
Console.Write ("First" + i.tostring () + "bit is:");
Console.WriteLine (Args[i]. ToString ());
}
}
}
Step 3: Compile and execute Main.cs, generate the Main.exe file
Step 4: Enter C:\>main a b C in the command line mode and hit enter to see the results
The output is:
Main function parameters length of args: 3
The No. 0 bit is: a
The 1th bit is: b
The 2nd bit is: C
Since the number of participants is unknown, it is not accepted that the input is arbitrarily multiple. Can also not be entered.
Role and interpretation of static void Main (string[] args) in C #