. Net naming convention example

Source: Internet
Author: User

1. Use Pascal rules to name methods and types. (I note: uppercase letters)
Public class DataGrid
{
Public void DataBind ()
{

}
}

2. Use the Camel rule to name the parameters of local variables and methods. (Note: The first word is lowercase, and the first letter of other words is uppercase. The author uses this method to name member variables)

Public class Product
{
Private string _ productId;
Private string _ productName;

Public void AddProduct
(String productId, string productName)
{

}
}
Supplement: Use Hungary to name local variables, method parameters, and controls.
Such as int iCount, string strName
Label lblTitle, Button btnSubmit, etc.

3. prefix "_" before all (private) member variables.

Public class DataBase
{
Private string _ connectionString;
}

Do not use public member variables, but use the get and set attributes in. net.

4. The interface name is prefixed with "I ".

Public interface IConvertible
{
Byte ToByte ();
}

5. Custom Attributes end with "Attribute.

Public class TableAttribute: Attribute
{

}

6. Custom exceptions end with exceptions.

Public class TableAttribute: Attribute
{

}

7. Name the method. It is generally named as a verb-object phrase.

Public class File
{
Public void CreateFile (string filePath)
{

}
Public void GetPath (string path)
{

}
}

8. The local variable name must be meaningful.

Do not use x, y, z, and so on. I, j, k, l, m, and n can be used in For loop variables.

Public class User
{
Public void GetUser ()
{
String [] userIds = {"ziv", "zorywa", "zlh "};

For (int I = 0, k = userIds. Length; I

}
}
}

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

Public class Product
{
Private string _ productId;
Private string _ productName;

Public void AddProduct (string productId, string productName)
{

}
}

10. Name namespace with meaningful names, such as the company name and product name.

Namespace Zivsoft // company name
{

}
Namespace ERP // Product Name
{

}

11. We recommend that you declare a local variable when it is closest to using it.

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

Public string GetTitle ()
{
String title = lbl_Title lblTitle. Text;
Return title;
}

14. Separate the referenced system namespace from the custom or third-party namespace with a line feed.

Using System;
Using System. Web. UI;
Using System. Windows. Forms;

Using CSharpCode;
Using CSharpCode. Style;

15. The file name should reflect the content of the class, preferably with the same name as the class. A class or a group of connected classes in a file.

16. The directory structure should reflect the namespace level.

17. The braces "{" need a new line.

Public Sample ()
{
//
// TODO: add the constructor logic here
//
}

<System. Web>
<HttpRuntime maxRequestLength = "10240"/>
</System. Web>

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.