It is good practice to keep our fields private but so far we had to create at least two methods to access or change their values.


Why not star using properties? You consume properties as fields and write them (almost) as methods.

Simple property example:


But why stop there we can add more functionality to our properties, like set our string name to Upercase, return default value or check if integer is a positive number.


A property that has both accessors is read-write property. Properties with only get accessor are called read-only properties, properties with only get accessor are called write-only properties.


When you only need basic property without any additional logic, you could create auto-implemented property without filed (actually compiler creates one for you).

Simple isn’t it 🙂