Overhead when using keyword this?

断了今生、忘了曾经 提交于 2019-12-24 23:16:10

问题


The scope of my question is solely ASP.NET, as the answer may be different for Java and any other C based language.

How much overhead is involved when using the keyword "this" within a class to dereference a property? It seems that I've seen certain sources try to discourage the use of "this" for dereferencing, but generaly I've just ignored them until now.


回答1:


I think it is just a style issue. As stated in the answer to this question, the compiler injects 'this' into implicit uses of this. I would use it for clarity.




回答2:


StyleCop recommended using this for all instance field reference.

And when compared to access the said field through a property, shouldn't it actually be faster (albeit unnoticable) by bypassing abstraction?




回答3:


No overhead.



来源:https://stackoverflow.com/questions/1105386/overhead-when-using-keyword-this

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!