Yes, the compiler generates a pair of get and set methods for a property, plus a private backing field for an auto-implemented property.
public int Age {get; set;}
becomes the equivalent of:
private int <Age>k__BackingField;
public int get_Age()
{
return <Age>k__BackingField;
}
public void set_Age(int age)
{
<Age>k__BackingField = age;
}
Code that accesses your property will be compiled to call one of these two methods. This is exactly one of the reasons why changing a public field to be a public property is a breaking change.
See Jon Skeet's Why Properties Matter.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…