使用ILspy的代码是:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
为什么检查num是否大于2146435071特别不应该只检查下溢&set num = Int.Max或任何大于min的值?
这与事实相关,该事实List<T>
使用数组作为内部存储,并且最大数组大小设置为2146435071
.
读取64位Windows上.NET中关于数组最大大小的数组的最大长度是多少.
您可以轻松创建自己的IList<T>
实现,该实现不会将数组用作内部存储,并且将允许多个2146435071
元素.当然,你仍然受限int.MaxValue
于最大元素数,因为IList<T>.Count
返回int
.
归档时间: |
|
查看次数: |
406 次 |
最近记录: |