62,046
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
const string head = "test headtest headtest headtest headtest headtest head";
List<string> sourceList = new List<string>();
for (int i = 0; i < 1000000; i++)
{
sourceList.Add(head + i.ToString());
}
List<string> dest1 = new List<string>();
List<string> dest2 = new List<string>();
DateTime tTime = DateTime.Now;
Console.WriteLine("{0}:{1}:{2}:{3}", tTime.Hour, tTime.Minute, tTime.Second, tTime.Millisecond);
dest1.AddRange(sourceList);
tTime = DateTime.Now;
Console.WriteLine("{0}:{1}:{2}:{3}", tTime.Hour, tTime.Minute, tTime.Second, tTime.Millisecond);
Console.WriteLine("++++++++++++++++++++++++++++++++++++++++");
tTime = DateTime.Now;
Console.WriteLine("{0}:{1}:{2}:{3}", tTime.Hour, tTime.Minute, tTime.Second, tTime.Millisecond);
foreach (var t in sourceList)
{
dest2.Add(t);
}
tTime = DateTime.Now;
Console.WriteLine("{0}:{1}:{2}:{3}", tTime.Hour, tTime.Minute, tTime.Second, tTime.Millisecond);
}
public virtual void AddRange(ICollection c)
{
this.InsertRange(this._size, c);
}
public virtual void InsertRange(int index, ICollection c)
{
if (c == null)
{
throw new ArgumentNullException("c", Environment.GetResourceString("ArgumentNull_Collection"));
}
if ((index < 0) || (index > this._size))
{
throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));
}
int count = c.Count;
if (count > 0)
{
this.EnsureCapacity(this._size + count);
if (index < this._size)
{
Array.Copy(this._items, index, this._items, index + count, this._size - index);
}
object[] array = new object[count];
c.CopyTo(array, 0);
array.CopyTo(this._items, index);
this._size += count;
this._version++;
}
}