1. Use Pascal's naming convention to name the type and method.
Public class someclass
{
Public somemethod (){}
}
2. Use camel naming rules to name parameters of local variables and methods.
Int number;
Void mymethod (INT somenumber)
{}
3. Use I as the prefix when naming interfaces.
Interface imyinterface
{...}
4. The private member variable uses M _ as the prefix.
Public class someclass
{
Private int m_number;
}
5. The custom attribute class uses attribute as its suffix.
6. The custom exception class uses exception as its suffix.
7. Use the phrase of the dynamic object structure when naming the method, such as showdialog ().
8. A method with a return value should have a name that can describe its return value, for example, getobjectstate ().
9. Use meaningful variable names.
10. Use the pre-defined type of C # instead of the alias in the system namespace to declare the variable.
Use object instead of Object
Use string instead of string
Use int instead of int32
11. Generally, uppercase letters are used for the type. When processing. Net types, use type as its suffix.
// Correct:
Public class Sequence List <K, T>
{...}
// Avoid using:
Public class category list <keytype, datatype>
{...}
12. Use meaningful namespaces, such as company names and product names.
13. Avoid using a fully qualified name. Replace it with the using statement.
14. Avoid writing the using statement inside the namespace.
15. Put all the framework-defined namespaces into one group, and the custom and third-party namespaces in another group.
Using system;
Using system. Collections.
Using system. componentmodel;
Using system. Data;
Using mycompany.
Using mycontrols;
16. Use the delegate reference to replace the explicit delegate instance.
Delegate void somedelegate ();
Public void somemethod ()
{...}
Somedelegate = somemethod;
17. Maintain a strict indent style.
A. Use three spaces for indentation.
B. Do not use tabs or other non-standard indentation, such as 1, 2, and 4 spaces.
18. The indentation of the comment and the encoding must be at the same level when writing the comment.
19. All comments must pass the spelling check. incorrect spelling is rough development. (For Chinese, statements must be fluent and easy to understand)
20. All member variables should be declared at the top, and a blank line should be used to separate them from attributes and methods.
Public class myclass
{
Int m_number;
String m_name;
Public void somemethod1 ()
{}
Public void somemethod2 ()
{}
}
21. Try to declare it when using the local variable for the first time.
22. The file name should reflect the class it contains.
23. When incomplete classes are used and parts are allocated to each file, P + ordinal numbers are used as the suffix naming file.
// In myclassp1.cs
Public partial class myclass
{...}
// In myclassp2.cs
Public partial class myclass
{...}
24. Always put braces on a new line.
25. The anonymous method and general (regular) method code use similar code Layout
A. rule: the braces (the brackets in the method body) must use a new line.
Delegate void somedelegate (string somestring );
// Correct:
Public void invokemethod ()
{
Somedelegate = delegate (string name)
{
MessageBox. Show (name );
};
Somedelegate ("Juval ");
}
// Avoid using:
Public void invokemethod ()
{
Somedelegate = delegate (string name) {MessageBox. Show (name );};
Somedelegate ("Juval ");
}
26. use empty brackets in the anonymous method without parameters.
A. If the anonymous method may be used in any delegate, parentheses can be omitted.
Delegate void somedelegate ();
// The correct method is:
Somedelegate somedelegate1 = delegate ()
{
MessageBox. Show ("hello ");
}
// Avoid using:
Somedelegate somedelegate1 = delegate
{
MessageBox. Show ("hello ");
}