contact ME

Use the form on the right to contact me.

Donate


Sydney
Australia

Blog

  

.NET 3.5 Language Enhancements - Automatic Property Getters and Setters

Eric Phan

Nice little time saver here, to declare a trivial property (just sets and returns a private variable) all you need to do in .NET 3.5 is:

public string FirstName { get; set; }

This syntax looks exactly like how you would declare an interface or abstract property. Previously you would have to write code like this:

private string _firstName;
public string FirstName
{
    get { return _firstName; }
    set { _firstName = value; }
}