给定这样的结构:
public struct SomeStruct
{
public SomeStruct(String stringProperty, Int32 intProperty)
{
this.StringProperty = stringProperty;
this.IntProperty = intProperty;
}
public String StringProperty { get; set; }
public Int32 IntProperty { get; set; }
}
当然,会生成一个编译器错误,读取The 'this' object cannot be used before its all fields are assigned to。
有没有办法为支持字段或属性本身分配值,或者我是否必须使用我自己的显式支持字段以老式方式实现属性?