Main () method, main method

Source: Internet
Author: User

Main () method, main method

  MainThe method is the entry point of the C # console application or window application. (Databases and services do not requireMainMethod as the entry point .) When the application is started,MainThe method is the first method to be called.

C # The program can have only one entry point. If multiple classes containMainYou must use the/main compiler option to compile the program to specifyMainMethod.

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
  • MainThe method is the entry point of the. exe program, where the program control flow starts and ends.

  • MainDeclare in a class or structure.MainIt 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.

  • MainThere are two types of responses:voidOrint.

  • DeclaredMainThe 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.

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.