Functions and explanations of static void main (string [] ARGs) in C #

Source: Internet
Author: User

Functions and explanations of static void main (string [] ARGs) in C #
Static indicates that the method is static. That is to say, the method is allocated memory when the program is compiled. When using the method, you do not need to generate a certain type of object and release it only when the program exits.
Void indicates that the method does not return a value, that is, the method does not have the urn keyword.
Main is the method name. Of course, this method is a special method. Main () is the main function, which is the entrance of the entire program. After the program is compiled, it is executed from here, this is also the reason why the main method is static, because this function must exist when nothing is done.


String [] ARGs indicates that the command line parameter is a string array, that is, you are in the command line (black box) the input parameters in can make multiple strings (in a sense, everything can be a command line parameter ).
The command window will pop up during running, where you can enter some parameters. String [] ARGs refers to the parameters you enter in the Command window. ARGs is used to process command line parameters. The command line parameter is the parameter that you pass to the program when running the program. It is optional and not required.

How to pass parameters to the C # main function? We can see that the C # main function has a string [] ARGs parameter, so do you know what practical functions it has? Let's talk about it in detail:
C # In the console application, we often see that the main function carries a string [] ARGs parameter, so do you know what it is useful?
Step 1: Create a console application named main. CS
Step 2: paste the following code.

 

1 using system; 2 3 class program {4 5 static void main (string [] ARGs) {6 7 int argslength = args. length; 8 9 console. writeline ("length of the main function parameter ARGs:" + argslength. tostring (); 10 11 for (INT I = 0; I <argslength; I ++) 12 {13 console. write ("th" + I. tostring () + "bit:"); 14 15 console. writeline (ARGs [I]. tostring (); 16} 17 18} 19}

 

Step 3: Compile and run main.csto generate the main.exe File

Step 4: Enter c: \> main a B C in command line mode, and press enter to view the result.

Output result:

Length of the main function parameter ARGs: 3

The fourth digit is:

The 1st bits are: B

The 2nd bits are: c

Because the number of parameters is unknown, you can enter any number of parameters without entering them.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.