Name agreement and style
1. Use the Naming specification naming specification of Pascal names and methods.
Public Class SomeClass
{
PUBLIC SOMEMETHOD () {}
}
2. Use the Camel naming specification to name the partial variables and methods.
Int number;
Void mymethod (int Somenumber)
{}
3. Use i as a prefix when named the interface.
Interface ImyInterface
{...}
4. Private member variables use m_ as a prefix.
Public Class SomeClass
{
PRIVATE INT M_NUMBER;
}
5. Custom attribute class uses Attribute as its suffix.
6. Customized exception class uses Exception as its suffix.
7. The phrase of the PV structure is used when naming methods, such as ShowDialog ().
8. There should be a name for returning values. There should be a name that can describe its return value, such as getObjectState ().
9. Use meaningful variable name.
10. Use the predefined type of C # without using its alias in the System namespace.
Use Object instead of Object
Use String instead of String
Use int instead of INT32
11. Typically, the type uses uppercase letters. Use TYPE as its suffix when processing the type of .NET.
//the correct one is:
Public Class LinkedList
{...}
/ / Avoid usage:
Public Class LinkedList
{...}
12. Using meaningful namespaces, such as using the company's name and product name.
13. Avoid using a fully qualified name. And use the USING statement to replace it.
14. Avoid writing the USING statement inside the namespace.
15. Place all the namespaces defined in a set of namespaces, custom, and third-party namespaces in another group.
Using system;
Using system.collections.
Using system.componentmodel;
Using system.data;
Using mycompany.
Using myControls;
16. Replace the explicit entrustment instance using the commissioned reference.
Delegate void somedlegate ();
Public void someMethod ()
{...}
Somedlegate somedlegate = someMethod;
17. Maintain strict indentation style.
a. Use 3 space indentation
b. Do not use Tabs or other non-standard indentation, such as 1, 2, 4 spaces.
18. The indentation and encoding of the annotation must be the same level when writing comments.
19. All comments must be inspected by spelling, and the wrong spell is rough development. (For Chinese, statement is easy to understand)
20. All member variables should be declared at the top while using a space line to separate them and attributes and methods.
Public Class Myclass
{
INT m_Number;
String m_name;
Public void someMethod1 ()
{}
Public void someMethod2 ()
{}
}
twenty one. State it when using local variables as much as possible.
twenty two. File names should be able to reflect the classes it contain.
twenty three. When an incomplete class is used and partially assigned to each file, use the P order as the suffix named file. // in myclassp1.cs
Public Partial Class Myclass
{...}
// in myclassp2.cs
Public Partial Class Myclass
{...}
twenty four. Always put the braces on a new line.
25. Anonymous method and general (regular) method code uses similar code layout
a. Status: Big brackets (braces of the method) must use new lines
Delegate void Somedelegate (String SomeString);
// the correct one is:
Public void invokeMethod ()
{
SomeDelegate somedelegate = delegate (String name)
{
Messagebox.show (name);
}
Somedelegate ("juval");
}
/ / Avoid usage:
Public void invokeMethod ()
{
Somedelegate somedelegate = delegate (string name) {messagebox.show (name);
Somedelegate ("juval");
}
26. Use empty parentheses in anonymous.
a. If an anonymous method is likely to be used in any commission, you can omit the parentheses.
Delegate void somedlegate ();
/ / The correct method is:
Somedlegate Somedelegate1 = delegate ()
{
Messagebox.show ("Hello");
}
/ / Avoid usage:
Somedelegate Somedelegate1 = delegate
{
Messagebox.show ("Hello");
}