>// don't do this at home > >public static void AddCollection<T>(this List<T> list, IEnumerable<T> items) > { > > if (items.Count() <= Tuning.AddRangeMinimumItems) // 128 > { > foreach (T item in items) > list.Add(item); > } > else > { > list.AddRange(items); > } > } >>
public static void AddCollection<T>(this List<T> list, IEnumerable<T> items) { list.Concat( items ); }Update: I made a short test with this using your original test and probably I am doing something wrong, results are unbelievably fast:
static void UseConcat() { int[] buf = new int[Size]; List<int> list = new List<int>(); for (int i = nTimes; --i != 0; ) { list.AddCollection(buf); list.Clear(); } }Cetin