Remember when I first learned computer programming in the C language, Main () {}, at that time did not understand what the entry function means, only know to copy the example on the book, one line to run printf look.
In C #, main () belongs to the main entry function, our knowledge C, C # belongs to the compiler language, can be imagined as a part of the beginning of the head of the program, the main () function into a statement to compile after the execution. If the HTML page is also called a programming language, then it is from the top to the next sentence (download) execution; JS is also from top to bottom execution, but JS is quite bizarre, variable scope to special treatment; in asp.net, it is generally Page_Load (object sender, EventArgs e) may be considered the main entrance.
string[] args parameter in Main ()
The Main () function must be decorated with static, that is, it must be statically, not instantiated--it can be instantiated--the program is finished (multithreading!?) )。 The default main () function is a formal parameter, in the form of static void Main (string[] args), which is a very important problem: many people think that the parameters must be taken only when the program involves requiring the user to enter a parameter value. That's a big mistake, and I've understood that before, and I didn't know it until today when I was writing this article. Please refer to the code below
Copy Code code as follows:
Using System;
/******************************
* chapter:c# difficult to break (four)
* 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 ()//Not added string[] args
{
Console.WriteLine ("Please enter your last name:");
String firstName = Console.ReadLine ();
Console.WriteLine ("Please enter your name:");
String lastName = Console.ReadLine ();
Console.WriteLine ("Your name is: {0}{1}", FirstName, LastName);
}
}
}
The second is that the type of the parameter can only be string[], otherwise it will compile the error
So what's the effect of this parameter? For example, you know, Notepad c:\boot.ini, or IEXPLORER.exe http://. www.g.cn, yes, the parameters inside are used to compile the EXE to add parameters, such as we can add a parameter min or hide, and then add the appropriate code can be implemented to minimize the operation of the program or hidden run.
return value of Main () function
Main () does not return a similar default, in addition to return int, and can only return int, this return int is not used much, in MSDN describes the use of batch bat invoke program execution of return results, based on the results to determine whether the program is executed smoothly. The return type does not appear in the console.
Download the source of this section