C # "II" Basic grammar (1)

Source: Internet
Author: User

1. C # Program Structure

The program structure diagram is as follows:

The meaning of each part of the code

1, the reference namespace;

2. Project name or namespace name;

3. Program class:

4, main function;

Gain insight into VS

1,. SLN: Solution Files

2. csproj: Project file

3.. cs: Class file

4. The relationship between solution files and project files and class files?

The procedure is as follows:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;//Reference Namespacesnamespace_2._1__CSHARP Program Structure {classProgram//Program class    {        Static voidMain (string[] args)//static void null no return value The main function is also the starting point for our program execution.{Console.WriteLine ("CSHARP Program Structure");        Console.readkey (); }    }}//namespace or project name

Operation Result:

2. Namespaces and identifiers, keywords

1. Namespaces

2. Is the way in. NET to provide the application code container so that it can uniquely identify its contents.

3. In C #, the keyword to create a namespace is namespace, which automatically joins the namespace when creating a console app in VS, in the form of a namespace space name.  namespaces exist in the form of "layers", if there are multiple layers, then ". Separate

Name space

In C #, sometimes namespaces are quite lengthy and cumbersome to enter, and it is not necessary to specify a particular class in this way.

1, to solve this problem, you can list the namespace of the class at the top of the file, preceded by the Using keyword, so that the method that accesses its space will be accessed within its class after referencing a name.

2, using has another role, is to give the namespace an alias, if the name of the namespace is very long, but also used in code more than once, and the user does not want the name of the namespace to be included in the using directive < For example: avoid class name conflicts; You can then specify an alias for the namespace.

3. Its syntax is as follows: using alias = namespace

identifiers, Keywords

1, the identifier is a program writer for constants, variables, data types, methods, functions, properties, classes, programs, such as the definition of the name.

2. For example, define a string variable:

string username;

3, the keyword for the C # compiler, with a specific meaning of the name, such as the program in the using, class, Static, void is a keyword. If you mistakenly use the keyword as an identifier, the compiler will produce an error, and we'll know immediately that something went wrong, so don't worry.

The provisions of identifiers

1, only by the capital letters, lowercase letters, numbers and underline _ composition;

2, must start with a letter or an underscore;

3, C language is case-sensitive, username and username are different identifiers;

4, if the C # keyword as an identifier in front of the identifier plus "@";

5. The name of the identifier is best recognized (English is available).

The procedure is as follows:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingMK = System.Console;//Create a new namespacenamespace_2._2_ namespace identifier keyword {classProgram {Static voidMain (string[] args) {Console.WriteLine ("This is an input statement"); Mk. WriteLine ("This is an input statement");        Console.readkey (); }    }}

Operation Result:

C # "II" Basic grammar (1)

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.