mohsen dorparasti mohsen dorparasti - 2 months ago 13
C# Question

how to add a range of items to the IList variable

there is no

AddRange()
method for
IList<T>
.

How can I add a list of items to a
IList<T>
without iterating through items and using
Add()
method ?

Answer

AddRange is defined on List<T>, not the interface.

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.

((List<myType>)myIList).AddRange(anotherList);