【发布时间】:2013-09-30 01:44:22
【问题描述】:
What is the difference between a Field and a Property in C#?
我已经阅读了上面的这个主题,但它充满了令人困惑的答案。
我想知道,用简单的英语,这段代码是在字段或属性下面吗? .如果是字段,什么是属性?如果是属性,什么是字段?
class Door
{
public int width { get; set; }
}
非常感谢。
【问题讨论】:
-
这是一个属性。如果是
public int width;,那就是一个字段。 -
接受的答案中的 cmets 对您没有帮助吗?
-
除了 SO 之外,您还查看过其他资源吗?
-
getter 和 setter 表示一个属性。
-
@minitech 将此作为答案发布,因此我可以选择您作为选择的答案:)