AddRange<T>()
I have created this AddRange<T>() method on ObservableCollection<T> because the LINQ Concat() method didn't trigger the CollectionChanged event. This method does.
Source
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace ReflectionIT.WPF {
public static class Extensions {
public static void AddRange<T>(this ObservableCollection<T> oc, IEnumerable<T> collection) {
if (collection == null) {
throw new ArgumentNullException("collection");
}
foreach (var item in collection)
{
oc.Add(item);
}
}
}
}
Example
list.AddRange(anotherList);
Author: Fons Sonnemans
Submitted on: 1 apr. 2008
Language: C#
Type: System.Collections.ObjectModel.ObservableCollection<T>
Views: 21022