一、命名规范
标识符 | 命名规则 | 实例 |
---|---|---|
命名空间 | Pascal | SingularityClub.UserCenter |
类型 | Pascal | public class User |
接口 | Pascal | public interface ISoftDelete |
方法 | Pascal | public User GetUsers() |
属性 | Pascal | public/protected int Age {…} |
委托 | Pascal | public delegate void InputString (string input) |
事件 | Pascal | public event EventHandler NameChanged |
枚举值 | Pascal | public enum TaskState |
常量 | Pascal | const int MaxCount |
参数 | Camel | public User SearchUser(string seachKey ) |
局部变量 | Camel | string myName |
(私有)字段 | _Camel | private string _userName |
全局变量 | _Camel | string _fieldName |
注
- 使用英文描述
- 避免使用缩写,若要使用缩写,缩写内容必须是常用专业术语,比如
Html
。 - 禁止使用意义相同,仅在大小写上有区别的命名。
- 程序集命名(同命名空间)采用身份名称(个人/团体/公司)+项目名+模块名。例如
SC.MemberWall.Web
。 - 接口名以字母 I 开头,例如
IEnumerable
。 - 避免在同一项目中的不同命名空间下定义名称相同的类或接口。
- 方法命名一般以动词开头,例如
GetUsers
、IsDisabled
。 - 对于static、readonly等修饰符,变量命名方式仅仅与访问权限有关,即public使用Pascal命名方式,private与protected使用_Camel命名方式。
二、注释规范
- 接口、类、方法、属性、变量,采用
///
自动生成的 xml 格式 - 代码行注释在所需注释代码上方使用
//
进行编写
三、类型成员的排列顺序
类型成员的排列顺序自上而下依次为:
1. 字段:私有、(受保护);
2. 属性:(私有)、受保护、公有;
3. 事件:私有、受保护、公有;
4. 构造函数:参数数量递减;
5. 方法:重载方法的排列顺序与构造函数相同,参数数量递减。