List.AddRange()
exists, but IList.AddRange()
doesn't.
This strikes me as odd. What's the reason behind this?
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 .
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With