using ILspy the code is :
private void EnsureCapacity(int min)
{
if (this._items.Length < min)
{
int num = (this._items.Length == 0) ? 4 : (this._items.Length * 2);
if (num > 2146435071)
{
num = 2146435071;
}
if (num < min)
{
num = min;
}
this.Capacity = num;
}
}
why is it checking if the num is greater than 2146435071 specifically shouldn't it just check for underflow & set num=Int.Max or anyother value greater than min?
This is connected to a fact, that List<T>
uses array as internal storage, and maximum array size is set to 2146435071
.
Read What is the maximum length of an array in .NET on 64-bit Windows about array max size.
You can easily create your own IList<T>
implementation which will not use array as internal storage, and will allow more than 2146435071
elements. Of course, you're still limited by int.MaxValue
as max number of elements, because IList<T>.Count
returns int
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With