C # Difficulty one by one (4): main function

Source: Internet
Author: User
Tags variable scope
Remember when I first learned computer programming in the C language, Main () {}, at that time did not understand what the entrance function means, only to copy the example of the book, one line to run printf to see.

In C #, Main () is the primary entry function, our knowledge C, C # belongs to the compilation language, can be imagined as a part of the beginning of a program of the head, the main () function into a statement after compiling the execution. If the HTML page is also called the programming language, then it belongs from the top to the next sentence (download) execution, JS is also from top to bottom execution, but JS quite strange, variable scope to special treatment; in ASP. Page_Load (object sender, EventArgs e) can be considered as the main entrance.

string[in Main ()] args parameter

The Main () function must use the static modifier, that is, it must be static and not instantiated--the program will be finished if it can be instantiated (multi-threaded!?). )。 The default Main () function is a formal parameter, such as the static void Main (string[] args), which is a very important question: many people think that the parameters are only required when the program involves requiring the user to enter parameter values. That's a big mistake, as I've understood before, and I just know when I'm writing this article today. Please refer to the following code

Using System; /****************************** * chapter:c# Difficulty one by one (iv) * 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 VO ID Main ()//here does not add 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[], or it will compile the error

So what does this parameter do? For example, you'll know, Notepad c:\boot.ini, or IEXPLORER.exe/HTTP// www.g.cn, yes, the parameters are used to compile the EXE to add the parameters, such as we can add a parameter min or hide, and then add the corresponding code to run the program to minimize the run or hide run.

The return value of the Main () function

Main () does not return a similar default, in addition to that, can return int, and only can return int, this return int is not much use, in MSDN describes the use of the batch bat called program execution of the return results, based on the results to determine whether the program is executed successfully. The return type does not appear in the console

The above is the C # difficulty one by one (4): main function of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

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