What's the max items in a List?

后端 未结 6 1407
闹比i
闹比i 2020-11-29 08:47

Anybody know what the max number of items in a List is?

How do I increase that size? Or is there a collection that takes infinite items? (as much as would fit in me

6条回答
  •  天涯浪人
    2020-11-29 09:50

    The List will dynamically grow itself to accomodate as many items as you want to include - until you exceed available memory!

    From MSDN documentation:

    If Count already equals Capacity, the capacity of the List is increased by automatically reallocating the internal array, and the existing elements are copied to the new array before the new element is added.

    If Count is less than Capacity, this method is an O(1) operation. If the capacity needs to be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.

提交回复
热议问题