Wednesday, July 31, 2013

Performance difference of inner-scoped variables and outer-scoped

Hi,


there can be a difference between them depending on the further usage of your myClass variable. If you don't use this variable in further steps there's no problem to put it into the for-loop.


From an optimization point of view I would prefer the first one, because this variable must not be instantiated every time your loop goes a step further. From a readability point of view the second option would be better (R# would suggest to go for the second option). Anyway, that will give you, if any, just a small performance boost. There are other things you should more care about when looking for performance optimization.




Best Regards. When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer. This helps us build a healthy and positive community.


@Horizon_Net | Blog


No comments:

Post a Comment