📌  相关文章
📜  'this' 对象在其所有字段都分配给之前不能使用 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:01.684000             🧑  作者: Mango

代码示例1
struct MyStruct
{
  public int SomeProp { get; set; }

  public MyStruct(int someVal) : this()
  {
     this.SomeProp = someVal;
  }
}
 // By calling :this() from your constructor declaration you let the base ValueType class initialize all the backing fields for the automatic properties. We cannot do it manually on our constructor because we don't have access to the backing field of an automatic property. ValueType is the base class of all structs.