【发布时间】:2009-08-18 15:32:10
【问题描述】:
我对 C# 中的自动属性有点困惑,例如
public string Forename{ get; set; }
我知道您通过不必声明私有变量来节省代码,但是当您不使用任何 get 或 set 逻辑时,属性的意义何在?为什么不直接使用
public string Forename;
我不确定这 2 个语句之间的区别是什么,我一直认为如果你想要额外的 get/set 逻辑,你会使用属性?
【问题讨论】:
标签: c# c#-3.0 automatic-properties