Given the following code:
public struct Foo
{
public Foo(int bar, int baz) : this()
{
Bar = bar; // Err 1, 2
Baz = baz; // Err 3
}
public int Bar { get; private set; }
public int Baz { get; private set; }
}
What does : this()
actually do? There is no default constructor, so what is it calling? Without this addendum, the whole thing crashes with errors.
Error 1 The 'this' object cannot be used before all of its fields are assigned to Error 2 Backing field for automatically implemented property 'Foo.Bar' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer. Error 3 Backing field for automatically implemented property 'Foo.Baz' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.