1. 变量命名
a. 生命周期
b. 变量类型
| 变量类型 | 变量缩写 |
|---|---|
| float | f |
| int | n |
| string | str |
c. 变量意义
使用Camel(驼峰命名法)命名.
using System;namespace TestNameSpace{public class C_TestClass{public static string s_str_helloName; //1public float m_f_testValue; //1public void TestFunction(int _n_testArg){int v_n_value = _n_testArg; //1}}}
类命名
使用Pascal(单词首字母大写)命名方式对命名空间、类型、枚举类型、枚举值、事件、属性、方法、常量进行命名
public class PersonManager {}
使用Camel()命名方式对参数、变量、字段进行命名。
private string userName;
禁止使用缩写,除URL、IO等能达成共识的缩写除外,使用缩写可全大写。
using System.IO;
接口以I做为前缀进行命名。
public interface IConvertor {}
抽象类以Abstract为前缀或者以Base为后缀进行命名。
public abstract class PersonBase {}
异常类型以Exception为后缀。
public class CustomException {}
在对任何东西命名时需要使用有意义的名称,并且保证单词拼写正确以及语法正确,避免使用拼音(地名等通用拼音除外)。
public string Name {get; set;} //√正确public string N {get; set;} //×错误
