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

后端 未结 5 1736
北海茫月
北海茫月 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:02

    In generics, such as List, they're still stored on the heap. The difference is that, internally, a List makes a single array of integers, and can store the numbers directly. WIth ArrayList, you end up storing an array of references to boxed integer values.

提交回复
热议问题