type
status
date
slug
summary
tags
category
icon
password
前言:
欢迎您来到我的知识海洋~
命名规范
- 本文档描述了开发中的命名规范。
- 如果没有明确指定访问级别(public/private等)则表示对所有访问级别生效。
概述
- 代码必须使用4个空格缩进,而不要使用制表符(tab)
- 使用using XXX,而不是new XXX.xxx()
- { }必须换行,且内部代码顶格书写
e.g.: if(true) { var tf = true; }
- 使用///对代码进行注释
e.g.: /// <summary> /// 这里对代码进行了注释 /// </summary> public string VariableName = "VariableName";
- 对于容易产生歧义的表达式您应该使用括号包裹
e.g.: if(variable1 + (++variable2) > 0) { }
- 模板必须为TStudlyCaps(驼峰式大写)以T开头
e.g.: public class Bootstrap<TType> { }
- 接口必须为IStudlyCaps(驼峰式大写)以I开头
e.g.: public interface IBootstrap { }
类名及函数
- 类名必须为StudlyCaps(驼峰式大写)
e.g.: public class Bootstrap { }
- 函数名必须为StudlyCaps(驼峰式大写)
e.g.: public void MyFunc() { }
变量,常量及属性
- 类公共变量名必须为StudlyCaps(驼峰式大写)
e.g.: public string VariableName = "hello";
- 类受保护变量名必须为StudlyCaps(驼峰式小写)
e.g.: internal string VariableName = "hello"; protected string VariableName = "hello"; protected internal string VariableName = "hello";
- 类私有变量名必须为camelCase(驼峰式小写)
e.g.: private string variableName = "hello";
- 类属性名必须为StudlyCaps(驼峰式大写)
e.g.: public string VariableName{ get; set; }
- 静态变量和常量必须为StudlyCaps(驼峰式大写)
e.g.: public const string VariableName = "hello"; public static readonly string VariableName = "hello"; public static string VariableName = "hello"; internal const string VariableName = "hello"; protected const string VariableName = "hello"; private const string VariableName = "hello";
- 参数必须为camelCase(驼峰式小写)
e.g.: public void FunctionName(Action callFunction) { var localVariable = callFunction; }
枚举
- 枚举名必须为EStudlyCaps(驼峰式大写) 以E开头
e.g.: public enum EApplicationEvents { }
- 枚举元素名必须为StudlyCaps(全大写 下划线区分)
e.g.: public enum ApplicationEvents { ON_START = 1, ONI_NITED = 2, }
命名空间
- 代码必须在项目名的根命名空间中
e.g.: namespace KyLin { }
- 组件代码必须在项目名.模块/系统名的命名空间中
e.g.: namespace KyLin.Module { }
文件
- 文件名必须和类名一致
- 文件必须只使用UTF-8而不使用BOM代码
- 一个文件中不能出现2个及以上的类,除非它是内部类或者类的重载
欢迎您在底部评论区留言,一起交流~
- 作者:Tdou
- 链接:https://www.tdouguo.com/p/csharp-norm.html
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。