When you create a property, you’re creating a set of accessor methods to read and write the property’s value. You also typically need a place to store the actual property value.
The data member where the property’s value is actually stored is known as a backing field, typically defined as a private field.
When you create an auto-implemented property, you don’t explicitly declare a backing field, but the compiler creates one for you in the IL that is generated. Your code doesn’t have access to the field.
1
2
| // Backing field not declared, created automaticallypublic int Age { get; set; } |
If you create the property explicitly, then you’ll declare the backing field yourself.
1
2
3
4
5
6
7
8
9
10
11
12
13
| // Backing fieldprivate int age;// Propertypublic int Age{ get { return age; } set { if (value != age) age = value; }} |

