C# properties: How are they instantiated?
- by Pedery
Hi!
This might be a pretty straightforward question, but I'm trying to understand some of the internal workings of the compilation.
Very simply put, imagine an arbitrary object being instantiated. This object is then allocated on the heap. The object has a property of type PointF (which is value type), with a get and a set method.
Imagine the get and the set method containing a few calculations for doing their work. How and where (stack/heap) and when is this code instantiated?
This is the background for this question:
I'm writing get and set methods for an object and these methods need to be accessed very frequently. The get and set code in itself is rather massive so I feared that in a worst case scenario the methods would be instantiated as an object or a value type with all internal code for every access of the property. On the other hand the code is probably instantiated when the main object is created and the CPU is simply told to jmp to the property code start. Anyway, this is what I want to have clarified.