In your example you use default property setter and getter but you can define your own property accessors for this purpose which is much cleaner.
publicclassAddress{privatestring_zipCode;publicstringZipCode{get=>_zipCode;set{// validationif(string.IsNullOrEmpty(value)){thrownewException("Invalid zip code");}_zipCode=value;}}}
In your example you use default property setter and getter but you can define your own property accessors for this purpose which is much cleaner.
docs.microsoft.com/en-us/dotnet/cs...
Hey Nicolas, you're totally right.
That's another way to do it :) Thanks for sharing!
It is the idiomatic way to do it.