给定这样的一个结构体:
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 all of its fields are assigned to。
是否可以给后备字段或属性本身分配值,或者我必须以我自己的显式后备字段实现属性的老方式?