A coworker asked me today how to add a range to a collection. He has a class that inherits from Collection
. There\'s a get-only property of that type t
Try casting to List in the extension method before running the loop. That way you can take advantage of the performance of List.AddRange.
public static void AddRange(this ICollection destination,
IEnumerable source)
{
List list = destination as List;
if (list != null)
{
list.AddRange(source);
}
else
{
foreach (T item in source)
{
destination.Add(item);
}
}
}