Add elements from IList to ObservableCollection

后端 未结 6 1693
臣服心动
臣服心动 2020-12-25 12:23

I have an ObservableCollection, and I\'d like to set the content of an IList to this one. Now I could just create a new instance of the collection..:

public         


        
6条回答
  •  醉酒成梦
    2020-12-25 13:21

    You could write your own extension method if you are using C#3+ to help you with that. This code has had some basic testing to ensure that it works:

    public static void AddRange(this ObservableCollection coll, IEnumerable items)
    {
        foreach (var item in items)
        {
            coll.Add(item);
        }
    }
    

提交回复
热议问题