如果在实例化对象时使用对象初始值设定项,对象构造函数是否可以访问已初始化的属性?构造函数是否可以访问已初始化的属性
public class ExampleClass {
public string proptery1 { get; set; }
public string property2 { get; set; }
public ExampleClass() {
if(!string.IsNullOrEmpty(property1)) {
...
}
}
}
ExampleClass exampleClass = new ExampleClass() {
property1 = "hello",
property2 = "world"
};
您使用的语法不是集合初始值设定项。它是对象初始值设定项。 – Grigory 2012-08-01 15:53:52
我问过这个问题,因为可能有不同的方式来做我想做的事情。我不知道我不知道什么。感谢您的低票... – bflemi3 2012-08-01 16:07:58