If I create a new ObservableCollection<T>
, and a CollectionChanged
listener as follows:
var c = new ObservableCollection<MyType>();
c.CollectionChanged += new NotifyCollectionChangedEventHandler(h);
...
void h(object sender, NotifyCollectionChangedEventArgs e)
{
IList newItems = e.NewItems;
// non generic IList! :(
}
Why isn't e.NewItems
an IList<MyType>
?
The ObservableCollection
is designed to support databinding scenarios in platforms like WPF where the databound controls don't care about the type of the collection they're bound to. Making the notifications generic would only make it much harder to write the controls without giving any benefit.
Presumably so that it can be used for non-generic collections as well as ObservableCollection<T>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With