【发布时间】:2010-10-31 22:18:29
【问题描述】:
在 C# 3.0 之前,我们这样做:
class SampleClass
{
private int field;
public int Property { get { return this.field } set { this.field = value } }
}
现在我们这样做:
class SampleClass
{
public int Property { get; set; }
}
(看妈妈!没有字段!) 现在,如果我想自定义 Getter 或 Setter,该字段必须像 C#2.0 中那样显式?
【问题讨论】:
-
顺便说一句 - 如果您使用 BinaryFormatter 并更改自动道具,请务必小心;它不健壮:marcgravell.blogspot.com/2009/03/…
标签: .net c#-3.0 properties automatic-properties