C#--属性--propfull和prop使用场所
1,propfull
private bool deviceState=false; [Browsable(true)]//设置这个属性是可见的 [Category("自定义属性")]//属性的分组,类别的名称 [Description("设备状态")]//属性的描述 public bool DeviceState { get { return deviceState; } set { deviceState = value; if (deviceState) { this.pic_start.Image = Properties.Resources.on__32绿色; this.pic_stop.Image = Properties.Resources.off__32灰色; } else { this.pic_start.Image = Properties.Resources.on__32灰色; this.pic_stop.Image = Properties.Resources.off__32红色; } } }
2,prop
[Browsable(true)]//设置这个属性是可见的 [Category("自定义属性")]//属性的分组,类别的名称 [Description("启动绑定的PLC地址")]//属性的描述 public string StartAddress { get; set; }
private string price; /// <summary> /// 单价(含税单价) /// </summary> public string Price { get { double d_price = Convert.ToDouble(price); double apiece = Convert.ToDouble(Apiece); double b = d_price / apiece; return b.ToString(); } set { price = value; } } /// <summary> /// 每 /// </summary> public string Apiece { get; set; }
总结:
如果需要有判断的,就用propfull
直接赋值使用的,就用prop