OdeToCode IC Logo

Automatic Properties

Wednesday, July 18, 2007

I wrote my first class with automatic properties in Orcas today...

public class FoodFactMessage
public int ID { get; set; }
public string Name { get; set; }

public int Calories { get; set; }

... then I found myself staring at the screen.

It's an interface!
No,it's a class!
Wait, it is a class!

I'd say the syntax is still growing on me.

I'm sure some people will say – why use properties at all? If you don't need special code in the get and set methods – why not just use a public field?

The quick answer is: reflection. There are many forms of magic that will only occur if you expose state using public properties.

Related Links