How Properties Work

Properties are nothing but one or two accessor methods that are grouped together by a piece of metadata. This allows code editors and runtime services like reflection to see them as a unique kind of member. Some other languages don’t have such a first-class treatment for concepts like properties (and indexers, and events, and so on) and rely on some naming convention instead:

class Person{    public string getName() { ... }    public void setName(string name) { ... }}

Although this works just fine, it makes tooling harder, and (what ought to be) properties are clustered together in the method list. Because get and set accessor pairs are such an established concept, .NET made them first-class metadata ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.