C # getting started with language (1)

Source: Internet
Author: User

Guide

C # Is a new language developed by Microsoft. It is as powerful as C/C ++ and provides rich network programming support and automatic memory management like Java, it is as easy to use as VB. The purpose of this article is to introduce this programming language to programmers who have not been familiar with C #. It is a basic getting started tutorial.
Author: Cactus Studio
2001-02-20

Source: http://journal.iftech.com/articles/0011_joey_CSharp/
C # Is a new language developed by Microsoft. It integrates the powerful functions of C/C ++ and the ease of use of Visual Basic. From the original language specification, we can see that C # is very similar to Java in terms of syntax, rich Web development support, and automated memory management. Therefore, if you have used C ++ or Java before, it would be quite easy to learn about C.

This article aims to introduce this programming language to programmers who have not been familiar with C. Whether you have used C/C ++ or Java before, you can start learning C # from this article #. The only assumption in this article is that you have a certain type of programming knowledge (such as experience in Object-Oriented Programming is better, but not necessary) and have a certain type of C # compiler.

The simplest C # Program

First, let's look at the standard Hello World Program. Create a new file HelloWorld. cs in the text editor and put the following code into the file:


// The first c # Program

Class HelloWorld {
Static void Main (){
System. Console. WriteLine ("Hello World! ");
}
}


Now, enter the directory for saving HelloWorld. cs in the doscommand window, and then execute:


Csc HelloWorld. cs


The command line compiles the source code and generates the helloworld.exe file. Run this execution file and you will see:


Hello World!


The following is an example. The first line of code is a line of comment, starting. Like C/C ++ and Java, "//" tells the compiler to ignore the content until the end of the row. Another Annotation method in C # is block annotation. The block comment starts from "/*" and ends.

The second important part of the program is the declaration of the Main () method of the fourth line (static void Mian (){). Every C # program contains a Main method, which is the start point and end point of program execution. Note that the Main () method of the HelloWorld class is defined as a static method. The Main method of the program will never be global, which means that the Main method must be included in the class. In this example, Main () is In The HelloWorld class (the Main method can also be included in the structure, but generally it is always in the class ).

The last key in the program is to output the text code to the Console, that is, "System. Console. WriteLine (" Hello World! ");". WriteLine is a method defined in the Console class. WriteLine () outputs the text to the standard output device and wrap the text. The Console class is contained in the System namespace (a set of classes. If you want to avoid using "System. console to indicate the full name of the Console class, you can add the "using System;" line of code at the beginning of the file, you can directly write the "Console. writeLine ("Hello World! ");".


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.