泛型VS拳击 [英] Generics vs boxing
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/139979/do-generic-interfaces-in-c-$p$pvent-boxing-net-vs-mono-performance">Do在C#prevent拳击通用接口? (.NET VS黑白性能)
我有一个快速的问题......通过使用仿制药,做我彻底摆脱装箱/拆箱操作?
I have one quick question... by using generics, do I completely get rid of boxing/unboxing operations?
例如,通过使用清单是否仍得到很多装箱/拆箱的?
For example, by using a List do I still get lots of boxing/unboxing?
我读过一些文档在互联网上,但没能解决这个具体问题...
I've read several docs on the internet but couldn't solve this specific question...
推荐答案
如果一个类被正确写入,然后使用仿制药将避免所有的装箱和拆箱。相反,刚刚在即时编译器将产生code为每个版本的正确恰当地处理值类型的类。
If a class was written correctly, then using generics will avoid all boxing and unboxing. Instead, the just-in-time compiler will generate code for each version of the class that correctly handles the value types appropriately.
这篇关于泛型VS拳击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!