Dim*_*nev 4 c# c++ using list stdvector
当添加大量元素时,System.Collections.Generic.List<T>它运行缓慢,因为当nums增加容量时,它必须复制所有元素.在C++中,这是固定的vector.reserve(n).我怎么能在C#中做到这一点?
System.Collections.Generic.List<T>
vector.reserve(n)
Ant*_*vin 14
使用容量属性:
list.Capacity = n;
或者您可以通过构造函数设置初始容量:
var list = new List<int>(n);
归档时间:
10 年,6 月 前
查看次数:
2714 次
最近记录: