In this code snippet, we will learn how to implement fields and properties in C#.
Properties provide us with a way to read from and write to our private fields. In other programming languages, you usually have to implement getter and setter methods for this. Using properties you have way more control over your fields. For example, you can add some code for input validation. This way you can ensure that a value will fit in a certain range of values before assigning it.
Let’s see how to use and implement fields and properties.