How to add a range of items to an IList?

后端 未结 5 624
忘了有多久
忘了有多久 2021-02-04 23:23

There is no AddRange() method for IList.

How can I add a list of items to an IList without iterating through the

5条回答
  •  醉梦人生
    2021-02-04 23:48

    Another answer using LINQ, provided the thing you're adding is a List or you are able to call ToList() on it:

    IEnumerable toAdd = new string[] {"a", "b", "c"};
    IList target = new List();
    
    toAdd.ToList().ForEach(target.Add);
    

提交回复
热议问题