Is Automatic Property Same as Property?

I was listening one session on TechEd (night after long party, yeah) and I was thinking about automatic properties - are they really exact equivalent to usual properties? Something made me suspicious, so I opened my laptop at first free moment and checked out what's going on.

 

NB! This blog is moved to gunnarpeipman.com

Click here to go to article

3 Comments

  • It depends.

    If the field that holds the value needs to be used inside the class very frequently, then performance-wise, automatic property is not the answer:

    Every single "Get" means calling a getter method, pushing on the stack, etc.

  • Is it a significant performance hit to the getter every time you need to reference the value? Just curious, I haven't done any benchmarking or anything.

  • Looking closely to the Disassembler, compiler has created a private instance "k__BackingField" by itself for automatic property. This way, we have increased the compiler overhead and shouldn't be considered under best practice.

Comments have been disabled for this content.