#261 – How Automatic Properties Look Under-the-Covers

The typical pattern for implementing an automatic property in a C# class is shown below–you do not need to define either a private backing variable, or the bodies of the get and set accessors.

    public class Dog
        // An automatic property
        public string Name { get; set; }

It’s interesting to use the IL DASM tool to see how this property is actually implemented.  Start up the IL Disassembler tool and then do a File | Open and load the .exe containing the property shown above.  You’ll see the following:

You can see the backing variable that the compiler automatically generated–k__BackingField.  You can also see the get and set accessors that the compiler automatically created, get_Name and set_Name.