Detailed explanation of C#-static void Main(string[] args)

Table of contents

Introduction:

Example:

Output result:​

Summarize:


Introduction:

In C#, what is the function of static void Main(string[] args) and what does it mean? !
This sentence is the declaration of the entry function, specifies the entry point of the C# program, and defines a static function named "Main". The parameter of this function is a string array named "args", which is used to accept command parameters. The meaning of this sentence is that the program starts executing from the Main function.
-'static': indicates that the method is a static method and can be called directly on the definition of a class or structure without instantiating an instance of the class or structure -'void':
indicates that the method has no return value
-'Main' : is the name of the method, the entry method of the C# program, and the default program entry method.
-'string[]args': is the parameter of the method, used to receive command line parameters. 'args' is an array of strings used to store the command arguments passed to the program

Example:

Output result:

Summarize:

In this example, the Main method serves as the entry point of the program. When the program starts, the operating system will call this method and pass in the command line parameters as a string array. Here we output the content to be printed to the console, and 'Console.ReadLine()' is used to wait for user input to prevent the console from closing directly. So here `static void Main(string[] args)` is the entry point of C#, which defines the startup logic of the program, and Can receive command line parameters. 

Guess you like

Origin blog.csdn.net/weixin_59272777/article/details/132343686