List<T>
is backed by a simple array, plus a size
field that indicates which portion of the array is actually in use. (to allow for future growth).
The array isn't resized unless you add too many elements or call TrimExcess
.
Remove
is O(n)
, since it needs to shift the rest of the list down by one.
Instead, you can use a LinkedList<T>
(unless you use random access), or write your own list which tracks an empty portion in front.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…