Where Are Value Types Stored In (C#) Generic Collections

后端 未结 5 1746
北海茫月
北海茫月 2021-02-08 09:31

It is true that generic collections perform better than non-generic collections for value types. (i.e. List vs. ArrayList).

But why is that, other than the boxing-unboxi

5条回答
  •  天涯浪人
    2021-02-08 10:14

    The performance gains in generics are generally only with regards to value types used with generics compared with value types stored in non-generic equivalents.

    This is because with generics value types do not need to be cast to object and stored on the heap (boxed). In fact they can remain on the stack which is more performant.

    http://msdn.microsoft.com/en-us/library/ms172181.aspx

提交回复
热议问题