This is kind of a noob question. I have a simple property
bool IsRoot { get { return parent==null; } }
that I call over and over many times from other properties and methods within the class (and derived classes)
I like to keep it like this because it makes the code readable (to me), but I am afraid that all the IsRoot
calls are going to slow me down as they might not be "inlined" in the final release code. What I mean by "inlined" is that they are replaced by a copy of the parent==null
evaluation in place of get_IsRoot()
.
Can someone explain to me when (or if) properties are inlined in C#, and for performance oriented applications are properties to be avoided, or not?
EDIT_1: Short answer is: Properties translate to pure function calls and they might, or might not be inlined depending on what JIT decides. Trust the system to make the right choices and don't worry about things that might affect things in the 5%-10% level, unless a profiler is used and the end result is fine tuned for performance.
Thanks for the links SO community, and I hope there was a way to award multiple correct answers. Sorry I had to pick one.