1. Use Pascal rules to name methods and types.
Public class DataGrid
{
Public void DataBind ()
{
}
}
2. Use Camel rules to name parameters of local variables and methods.
Public class Product
{
Private string _ productId;
Private string _ productName;
Public void AddProduct (string productId, string productName)
{
}
}
3. prefix "_" before all member variables.
Public class DataBase
{
Private string _ connectionString;
}
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 NullEmptyException: Exception
{
}
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 <k; 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.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
//
}