O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Auto-Implemented Properties

C# 3.0 introduced a feature called auto-implemented properties to reduce the “syntactic ceremony” involved in creating “simple properties” that are nothing but smart fields. Instead of having to declare the backing field and a property accessing that field manually, the following syntax takes care of it all:

class Person{    public string Name { get; set; }    public int Age { get; set; }}

The preceding code is turned into this equivalent:

class Person{    private string <Name>k__BackingField;    private int <Age>k__BackingField;    public string Name    {        get { return <Name>k__BackingField; }        set { <Name>k__BackingField = value; }    }    public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required