The note of learning ASP. NET [7] used notepad to develop the first. Net Program helloworld with CSC

Source: Internet
Author: User
In February May 11, we were so energetic today .. The third note of today. I have just read the tutorial to write a classic helloworld. Here I use NotePad to write C # programs and use the CSC (compiler) provided by. NET Framework to compile and execute it in the command line. Under normal circumstances, the. NET operation does not require custom environment variables. Therefore, when we run CSC directly in the command line Prompt window (CMD), we cannot find the running program. Below I will record the source code and the compilation process using the command line. The helloworld program is very simple. use NotePad to write the code as follows: Class helloworld {public static void main () // In the above line of code, public indicates that this method can be accessed by other classes, in general, you can omit // void to declare that this method has no return value. // main is the name of this method. Note that m must be capitalized, which is also the entry point of the entire program, an application has only one main method // static declaration. This is a static method, static methods can be called directly without using the new ID to create an instance. // Why must the main method be identified as static? The reason is as follows: // first, we need to know that the method marked as static does not have to use the new identifier to create an object when calling, but does not mean that this object is not actually created, // On the contrary, when a static method is called, an instance of the class of the static method is automatically created in the runtime environment. // The runtime environment does not actually know the name of the class where the main method is located when running this program, therefore, you cannot create an instance of the class // where the main method is located and then run the main method. After we mark the main as static, in the runtime environment, you can directly call the main method to automatically create an instance of the class where the main method is located. {// We only output helloworld system. Console. writeline ("Hello world! "); // The command line window waits for key input to prevent our helloworld from flashing when we directly run the EXE file: system. console. readkey () ;}enter the above Code and save it as the suffix. CS file. Here I save it as helloworld. CS to drive F. Next, if Visual Studio is installed, you can find the Visual Studio directory in the Start Menu, go to the Visual Studio Tools directory at the next level, and select "Visual Studio 2008 command prompt ". Alternatively, if you have installed the. NET Framework SDK, you can find the SDK command prompt in its directory in the Start Menu, which of the following entries is the same. After running, a command line Prompt window will be opened and run CSC directly. This means that your compiler is running, but you will be prompted not to specify the input. Now we can use it to compile our program, and use the command CD to switch the current path to our helloworld. the directory where the CS file is located (CD/switch to the root directory, CD .. switch to the upper-level directory, and enter the CD directory name or directory path.) Run CSC helloworld. CS. The hosts file and run it directly to view our hello World! Of course, we can also directly input helloworld.exe to run it in the prompt window. PS. Enter path in the vs Command Prompt window. You will see the path we used.
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.