C# 3.0 auto-properties — useful or not?

We use them all the time in Stack Overflow.

You may also be interested in a discussion of Properties vs. Public Variables. IMHO that's really what this is a reaction to, and for that purpose, it's great.


Yes, it does just save code. It's miles easier to read when you have loads of them. They're quicker to write and easier to maintain. Saving code is always a good goal.

You can set different scopes:

public string PropertyName { get; private set; }

So that the property can only be changed inside the class. This isn't really immutable as you can still access the private setter through reflection.

As of C#6 you can also create true readonly properties - i.e. immutable properties that cannot be changed outside of the constructor:

public string PropertyName { get; }

public MyClass() { this.PropertyName = "whatever"; }

At compile time that will become:

readonly string pName;
public string PropertyName { get { return this.pName; } }

public MyClass() { this.pName = "whatever"; }

In immutable classes with a lot of members this saves a lot of excess code.


The three big downsides to using fields instead of properties are:

  1. You can't databind to a field whereas you can to a property
  2. If you start off using a field, you can't later (easily) change them to a property
  3. There are some attributes that you can add to a property that you can't add to a field