Automatic properties in C#3

Mon, March 5, 2007, 04:36 AM under Orcas | VisualStudio
I was looking at Ander's slides from Tech Ed Europe and he had one about automatic properties but watching the video he did not cover that in his session. It is the simplest concept imaginable and hence it deserves a simple short blog entry.

In C#3, you can write code like this:
        public string Name
{
get;
set;
}
The compiler generates code like this:
        private string XX;
public string Name
{
get { return XX; }
set { XX = value; }
}
, where XX is not directly accessible to you in code of course. This only works for properties with both getter and setters.

Get the March CTP to try it out yourself.