O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required