c#编程规范

zhangmike
博客专家认证
2002-12-10 01:55:04
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
...全文
55 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdn_bob 2002-12-10
  • 打赏
  • 举报
回复
不是吧,是e文呀!
genuinekl 2002-12-10
  • 打赏
  • 举报
回复
你是不是需要,还是讨论
如果需要的话,给我留言我这有一份

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧