Search code examples
c#overheadautomatic-properties

Aren't automatic properties in C# causing ovehead?


When I have automatic propertie and I try to access it from within it's class, it seems like an overhead, because I use a function to access a member of my class instead of just accessing it directlly.

If this is correct, maybe I should consider not to use automatic properties in such cases?


Solution

  • Have you measured any theoretical overhead and found it to be significant? That's the key to making performance-based decisions.

    In this case, I'd thoroughly expect the JIT to inline automatically-implemented properties, removing any performance overhead. (I seem to remember seeing a case with float / double where this wasn't the case, but that was a while ago - and even then the overhead was pretty small.)