c#编程规范
C# Coding Standards Summary
[{}]
Rule, the the closing bracket must always be on the next line and on the same position with the opening bracket
Example:
if (a<b)
{
.....
}
[Tabs]
Rule: Always use one tab after the bracket
Example
if (a<b)
{
if (b<c)
{
if (c<d)
{
a=1;
b=1;
}
}
}
[Classes]
Rule: always start with a capital letter; every successive word starts with a capital letter
Example: HelloWorld
[Interfaces]
Rule: always starts with a capital letter ‘I’, then every word starts with capital letter
Example: IComputer
[Variables]
Rule: starting 4 to 5 letters in small characters, then every word starts with a capital letter and must not exceed 3-4 characters
Example: startFun
[Functions]
Rule: starts with a capital letter and goes up to 3-4 characters, then every word starts with a capital letter and must not exceed 3-4 characters
Example: OpenSeaSame and so on…
[Class members]
Rule: All class members must be private. There are few exceptions (in the structures) where the variables must be public. Should you have to have a public variable, please provide the comment why.
[Access to class members]
Rule: Use property (get and set) for accessing your members. The name of the property must match the name of the variable and start from the upper case.
Example:
public class Abcd
{
.....
private int a;
public int A
{
get
{
return this.a;
}
set
{
this.a=value;
}
}
}
[Using of this]
Rule: Use this for all the class memebers.
Example:
public class Abcd
{
private int a;
public Abcd(int a)
{
this.a=a;
}
}
http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconnetframeworkdesignguidelines.asp