Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't IList support AddRange

Tags:

c#

.net

ilist

List.AddRange() exists, but IList.AddRange() doesn't.
This strikes me as odd. What's the reason behind this?

like image 752
Boris Callens Avatar asked Jul 18 '12 09:07

Boris Callens


People also ask

How do I add AddRange to IList?

You can declare the variable as List<T> instead of IList<T> or cast it to List<T> in order to gain access to AddRange .

What is the difference between list and IList in C#?

The main difference between List and IList in C# is that List is a class that represents a list of objects which can be accessed by index while IList is an interface that represents a collection of objects which can be accessed by index.

What is IList C#?

In C# IList interface is an interface that belongs to the collection module where we can access each element by index. Or we can say that it is a collection of objects that are used to access each element individually with the help of an index. It is of both generic and non-generic types.


1 Answers

Because an interface shoud be easy to implement and not contain "everything but the kitchen". If you add AddRange you should then add InsertRange and RemoveRange (for symmetry). A better question would be why there aren't extension methods for the IList<T> interface similar to the IEnumerable<T> interface. (extension methods for in-place Sort, BinarySearch, ... would be useful)

like image 155
xanatos Avatar answered Sep 25 '22 04:09

xanatos