#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.


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: