C #, in-depth understanding (3)

Source: Internet
Author: User

9. C # practical programming exercises ABC

1. Use Visual Studio. NET to write C # programs
Visual Studio. NET is the next-generation flagship development environment of Microsoft. In this environment, we can see that Microsoft integrates all development tools into an IDE. We are pleasantly surprised to find that we have a code editor that applies to all programming languages. In addition, this environment also has an HTML editor, an XML editor, an SQL Server interface, and a Server Explorer.
Next, we will learn how to compile C # programs in Visual Studio. NET.
Initial page
After VS. NET is started, we will see a different scene from the previous version. In fact, it looks more like Visual J ++. The initial Page is displayed at the beginning. This is an HTML page, from which we can see links to the online Microsoft web site, a list of existing solutions, and creating your own Profile).
Create a C # console application
Creating a C # application in Visual Studio. Net is simple. After you click "Create New Project", a dialog box is displayed. Select one of the multiple engineering samples in this window. Here, we select the Visual C # project file. The following dialog box is displayed:

 

Then select "Console Application" (Console Application), name it "Hello1" (no quotation marks are required), and click "OK",. NET to generate the shell of the application ).
Now let's analyze the code in this shell.
First, we will see the keyword namespace ). You can simply consider a namespace as a combination of classes. The namespace in C # is similar to the namespace in C ++, but it also has some additional features. In addition, it is similar to the package keyword in Java.
The following statement is the using command, which tells the compiler to find unknown classes in the System library .. NET carries a set of scalable system libraries, and their namespaces determine their scope. In C #, All I/O operations are part of the system library, not part of the language itself.
Then we can see the "public class Class1" declaration. As an advanced object-oriented development language, all the code in C # must be included in a class and there is no global function or data.
The program also contains a method Main, which is the entry gate for all C # programs.
Modify the code
Now we need to add some code to execute some useful operations. The first thing is to switch the window in the upper-right corner to the Class View, expand the "Hello1" namespace, and click "Class1" Class. In the Properties window, change the name to Hello. The current code window is changed:

Move the cursor to the TODO comment in the Main method and enter the "Console" command. Note what happened:

You can see that the system automatically lists methods related to the Console class. Select WriteLine and write the following line:
Console. WriteLine ("Hello from VS. NET! ");
Run
Now, select "Build" from the "Build" menu, and then select "Start Without Debugging" from the "Debug" menu ). Finally, the console should display "Hello From VS. NET! . This shows that we have achieved success :-)

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.