In C#, if I declare an auto-implemented property, why do I have to declare BOTH the get and set part?
i.e.
public string ThisWorks { get; set; }
public string ThisDoesnt { get; }
Isn't this just syntactic sugar - i.e. the compiler inserts a private field for the property? So why the problem?
Curious.
If you didn't have a setter - then how would you ever set the property?
Incidentally, you can specify the accessibility, eg:
public string Foo
{
get;
private set;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With