I'm new to C#, just a question on default constructor and automatic properties. Based on a question on stackoverflow: How can I set the value of auto property backing fields in a struct constructor?
so we have the following struct
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; }
}
but how come it compiles fine to me without calling the default constructor by :this()
?
Another question is why does the same rule not apply to classes? can you have an automatic property without a default constructor?