No, ICollection<T> does not have an AddRange method - and even if that happened, you tried to dereference null , which would throw a NullReferenceException . You did not specify a collection to add the list to ... what exactly are you trying to do?
You could create (say) a new List<T> - and this has the advantage of already having a constructor that can accept IEnumerable<T> :
public static ICollection<T> Add<T>(this IEnumerable<T> list) { return new List<T>(list); }
However, at this point, you really just redefined Enumerable.ToList() and gave it a different return type ...
If you want to add everything to an existing collection, you might need something like the following:
public static ICollection<T> AddTo<T>(this IEnumerable<T> list, ICollection<T> collection) { foreach (T item in list) { collection.Add(item); } return collection; }
Jon skeet
source share