Answers for "the 'this' object cannot be used before all of its fields are assigned to"

C#
0

the 'this' object cannot be used before all of its fields are assigned to

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.
Posted by: Guest on April-19-2021

Code answers related to "the 'this' object cannot be used before all of its fields are assigned to"

C# Answers by Framework

Browse Popular Code Answers by Language