Is there any difference between auto-implemented properties and manually implemented ones, from a performance point of view?
3 Answers
because as we know they are created at runtime
Auto-properties aren't created at runtime, they are generated at compile time. Very much like using
, they are helpful syntactic sugar to reduce the amount of typing you need to do. They simply translate into code you would have written manually anyway.
There is no performance difference. Aside from the backing field name, the resulting code is the same as if you did it manually.
As @dasblinkenlight highlights, the backing name, being a "safe name" (as in, could never create it in C#) can cause serialization issues where the name cannot be handled correctly.

- 63,413
- 11
- 150
- 187
-
Yes, this is correct. You can verify this with a decompiler of your choice, like ildasm. Some tools like Reflector and dotPeek might be "clever" enough to convert it back into an auto property. – vcsjones Jul 13 '12 at 13:55
-
2+1 You may want to mention that the naming difference may be of importance when serializing objects of classes with auto properties. – Sergey Kalinichenko Jul 13 '12 at 13:56
-
@dasblinkenlight I'll leave your comment for it. The question wasn't about serialization or common gotchas with auto-properties. – Adam Houldsworth Jul 13 '12 at 14:00
-
@dasblinkenlight actually, for the sake of a sentence, I'll add it - I wasn't aware of this until another SO question a while ago pointed it out :-) – Adam Houldsworth Jul 13 '12 at 14:05
-
Thanks for the answer, obviously i was confused that they are created at runtime, but now i understand that they are created at compile time so when running there is no performance gain. – Freeman Jul 13 '12 at 14:11
There's no difference. Automatic properties are converted to normal properties at compile time. so this:
public int Prop { get; set; }
is made into something equivalent to this:
private int _PropField;
public int Prop {
get { return _PropField; }
set { _PropField = value; }
}

- 39,020
- 8
- 103
- 127
Auto properties are syntactical sugar means they are shorthand of writing properties
Taken from MSDN :
In C# 3.0 and later, auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. They also enable client code to create objects When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field can only be accessed through the property's get and set accessors.
http://msdn.microsoft.com/en-us/library/bb384054(v=vs.90).aspx

- 11,077
- 3
- 28
- 43