TechEd 2007. VStudio 2008, C# 3, Automatic Properties

Just following the previous post, I keep talking about the session by Daniel Moth (http://www.danielmoth.com/Blog ), yesterday in the TechEd.

He showed another C# 3 new feature that is extremely useful: Automatic Properties.

You not tired about writing something like this?

private int mNumCustomers;
public int NumCustomers
{
get{return mNumCustomers;}
set{mNumCustomers = value;}
}

This is a pain in the ass... You are supposed to use properties, to be clear, clean, robust, elegant, and a good christian, but writing them is painful. Yes, refactoring helped quite a bit, but it´s still something... don´t know... slow and uncomfortable.

Well, Microsoft says that is there to make us more productive, as there it is:

Automatic Properties a.k.a JustWriteThis:

public int NumCustomers{get; set;}

The language will take care of creating the private equivalent variable, just for us. We don´t need to write it. Just specify if you want the get and set, the get only, etc, and there it is!

Again, more productivity...