You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think if (newCapacity < min) newCapacity = min; should be removed, I have added items to the full capacity of the list but never hit breakpoint on line newCapacity = min;, Can someone tell the purpose of this line as well?
private void EnsureCapacity(int min) {
if (_items.Length < min) {
int newCapacity = _items.Length == 0? _defaultCapacity : _items.Length * 2;
// Allow the list to grow to maximum possible capacity (~2G elements) before encountering overflow.
// Note that this check works even when _items.Length overflowed thanks to the (uint) cast
if ((uint)newCapacity > Array.MaxArrayLength) newCapacity = Array.MaxArrayLength;
if (newCapacity < min) newCapacity = min;
Capacity = newCapacity;
}
}
The text was updated successfully, but these errors were encountered:
Without that line, the array would grow, but it would not honor min. For example, if you have a list with Capacity = Length = 4 and AddRange a collection with 6 items, removing that line would grow the list to 8, when it needs to grow to 10.
I think if (newCapacity < min) newCapacity = min; should be removed, I have added items to the full capacity of the list but never hit breakpoint on line newCapacity = min;, Can someone tell the purpose of this line as well?
The text was updated successfully, but these errors were encountered: