I still remember the C language, main () {}when I first got familiar with computer programming in college. At that time, I still didn't understand what the entry function meant. I only knew how to copy the example in a book, run printf one by one.
In C #, main () is a main entry function. We know that C and C # Are compilation languages.ProgramAt the beginning of the header, the main () function enters the statement-by-statement Method for compilation and execution. If an HTML page is also calledProgramming LanguageThen it is executed by a sentence (download) from top to bottom. JS is also executed from top to bottom, but JS is quite strange and the variable scope should be specially treated; in Asp.net, page_load (Object sender, eventargs e) can be considered as the main entry.
String [] ARGs parameter in main ()
The main () function must be modified using static, that is, it must be static and cannot be instantiated. -- if it can be instantiated, the program will be finished (multithreading !?). The default main () function is a form parameter, such as static void main (string [] ARGs). A very important problem here is: many people think that the parameter must be included only when the program requires the user to enter the parameter value. This is a big mistake. I used to understand this too. Today I am writing this article.ArticleWhen querying information. See the followingCode Copy codeThe Code is as follows: using system;
/******************************
* Chapter: C # The difficulties are solved one by one (4)
* Author: Wang Hongjian
* Date: 2010-1-15
* Blog: http://www.51obj.cn/
* Email: walkingp@126.com
* Description: error-prone Main Parameter understanding
****************************/
Namespace testmain
{
Class Program
{
Static void main () // No string [] ARGs is added here
{
Console. writeline ("Enter your surname :");
String firstname = console. Readline ();
Console. writeline ("enter your name :");
String lastname = console. Readline ();
Console. writeline ("Your name is: {0} {1}", firstname, lastname );
}
}
}
The second is that the parameter type can only be string [], otherwise the compilation will be incorrect.
So what is the role of this parameter? For example, you will know, notepad c: \ boot.ini, ipolicer.exe http://www.g.cn, yes, the parameters inside is used to compile EXE to add parameters, such as we can add a parameter min or hide, then add the corresponding code to minimize or hide the running during the program running.
Return Value of main () function
main () does not return a similar result by default. In addition, int can be returned and only int can be returned. There are not many usage cases of int returned, on msdn, the returned results of execution of the bat call program are described, and the execution result is used to determine whether the program is successfully executed. The return type is not displayed on the console. "
download the source code in this section