C # basic 1

Source: Internet
Author: User

Naming rules and naming habits

C # Some common naming conventions: Pascal case-sensitive: the first letter of all words is capitalized, And the other letters are lowercase.

Camel case: except the first word, the other letters are in lower case.

1. The class name is in Pascal case
Public class helloworld {...}

2. Use Pascal case
Public class helloworld {void sayhello (string name ){...}}

3. Variables and method parameters are in the camel case-sensitive format.
Public class helloworld {int totalcount = 0; void sayhello (string name) {string fullmessage = "hello" + name ;...}}

4. Do not use the Hungary method to name variables.
In the past, most programmers liked it-taking the data type as the prefix of the variable name and M _ as the prefix of the member variable. For example:
String m_sname; int Nage;
However, this method is not recommended in. Net encoding specifications. All variables are in the camel case format, instead of using the Data Type and M _ as the prefix.

5. Use meaningful and descriptive words to name variables
-Do not use the abbreviation. Use name, address, salary, and so on to replace Nam, ADDR, Sal
-Do not use single-letter variables such as I, n, x. Use index, temp, etc.
Variable exceptions used for loop iteration:
For (INT I = 0; I <count; I ++ ){...}
If a variable is used only for iterative counting and does not appear elsewhere in the loop, many people prefer to use a single letter variable (I) instead of another name.
-The variable name does not contain underscores (_).
-The namespace must be named in standard mode.

6. The file name must match the class name.
For example, for the class helloworld, the corresponding file name should be helloworld. CS (or, helloworld. VB)

7. indent and interval
Indent with tab. Do not use spaces ..
The annotation must be aligned with the code ..
The curly arc ({}) must be aligned with the code outside the brackets ..
Use a blank line to separate the logical grouping of code ..
In a class, each method requires an empty row, or only one row can be separated.
The Arc should be an independent line, unlike if, for, and so on ..
Each operator and parentheses have a space ..
Good:
If (showresult = true) {for (INT I = 0; I <10; I ++ ){//}}
Bad:
If (showresult = true) {for (INT I = 0; I <10; I ++ ){//}}

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.