1.字段
字段是一个类内部使用的变量,不应该使用public修饰符公开,命名时规范(个人习惯)如下:
protected string messageName;
private int messageLength;
2.属性
属性是一个类提供给外部使用访问的变量,一般通过get/set去定义读写权限,命名时规范(个人习惯)如下:
public string MessageName => messageName; //只读属性
public int MessageLength
{
get { return messageLength; }
set { messageLength = value; }
}
3.类变量命名时规范(个人习惯)如下:
private static BluetoothMessage BluetoothMessageInstance = new BluetoothMessage();
4.常量命名时规范(个人习惯)如下:
private const string MESSAGE_NAME = "BluetoothMessage";//编译时常量
private readonly string MESSAGE_ID;//运行时常量,可在构造函数中赋值
以上。