Start the C # Journey,

Source: Internet
Author: User

Start the C # Journey,

Note

/// <Summary>

/// 3. Document comment

/// </Summary>

Private static void Test ()

{

Console. WriteLine ("Hello world! "); // 1. Single line comment

Console. ReadKey ();

 

/* 2. Block comment

Console. WriteLine ("Hello world! ");

Console. ReadKey ();

*/

}

Namespace

C # programs are organized using namespaces. A namespace is used both as an "internal" organizational system of a program and an organizational system exposed to "external" (that is, a method to disclose its own program elements to other programs ). To call a class or method in a namespace, you must first use the using command to introduce the namespace, the using command imports the type members in the namespace identified by the namespace name into the current compilation unit, so that you can directly use the identifiers of each imported type, without the need to add their fully qualified names.

The namespaces in C # are like a warehouse with different types of storage, and the using command is like a key. The namespace name is like the name of the warehouse, you can use the key to open the warehouse with the specified name to obtain the required items in the warehouse.

Namespace: namespace name {}

The basic form of the using command: using namespace name;

Main Method

C # Main () is the entry point of the C # application. To execute this function, you can execute the application. That is to say, at the beginning of the execution process, the Main () function will be executed. When the Main () function is executed, the execution will be completed.

C # four Main functions:

1) static void Main (){}

2) static int Main (){}

3) static void Main (string [] args ){}

4) static int Main (string [] args ){}

 

1) The Main function of the Main program has four versions.

2) there cannot be more than two Main functions in a program, and there is only one

3) The Main function can only return int type. If 1 is returned, the call from the command line fails. Otherwise

4) The parameters are stored in the string array args during command line transmission. Use the Length attribute to test the number of input parameters.

5) use the foreach statement to retrieve all parameters

6) The program entry is mainly used by other programs to execute the program functions.

Identifier and keyword

An identifier refers to the word used to represent a thing in a program. For example, the Console class of the System namespace and the WriteLine method of the Console class are all identifiers. The identifier name has three basic rules:

1) An identifier can only contain numbers, letters, and underscores.

2) The identifier must start with a letter or underline.

3) The identifier cannot be a keyword.

Keywords refer to words with special meanings in the C # language. They are reserved by C # And cannot be used at will. For example, both static and void are keywords.

Note: When naming classes, variables, and methods, do not duplicate names with identifiers and keywords.

Programming Specification

A) code writing rules

Try to use interfaces and then use classes to implement interfaces to improve program flexibility.

A line must not exceed 80 characters.

Do not manually change the computer-generated code. If you must change the code, make sure it is the same as the computer-generated code.

Note must be written for key statements (including declaring key variables.

It is recommended that local variables be declared in the nearest place to use it.

Do not use goto statements unless they are used to jump out of a deep loop.

Avoid writing more than five parameters. If you want to pass multiple parameters, the structure is used.

Avoid writing too much code... Catch module.

Avoid placing multiple classes in the same file.

When generating and constructing a long string, you must use the StringBuilder type instead of the string type.

The switch statement must have a default statement to handle exceptions.

For the if statement, use a pair of "{}" to include the statement block.

Try not to use the this keyword for reference.

B) Naming rules

Use Pascal rules to name methods and types. Pascal naming rules indicate that the first letter must be capitalized, and the first letter of the Connected Word is capitalized. Example: DataGrid

Use the Camel rule to name the parameters of local variables and methods. This rule indicates that the first letter of the first word in the name is in lowercase. Example: strUserName

All member variables are prefixed with "_". Example: _ connnectionString

The interface name is prefixed with "I ". Example: Iconvertible

Method, which is generally named as a verb-object phrase. Example: CreateFile

All member variables are declared at the top of the class and separated from the method by a line break.

Use a meaningful namespace, such as a company name or product name.

Use the value of a control to name local variables whenever possible.

 

 

Summary after reading C # From getting started to proficient

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.