There is no AddRange() method for IList<T>.
How can I add a list of items to an IList<T> without iterating through the items and using the Add() method?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
AddRangeis defined onList<T>, not the interface.You can declare the variable as
List<T>instead ofIList<T>or cast it toList<T>in order to gain access toAddRange.This is not good practice (see comments below), as an
IList<T>might not be aList<T>, but some other type that implemented the interface and may very well not have anAddRangemethod – in such a case, you will only find out when your code throws an exception at runtime.So, unless you know for certain that the type is indeed a
List<T>, you shouldn’t try to useAddRange.One way to do so is by testing the type with the is or as operators (since C# 7).