gnaix gnaix - 1 month ago 18
C# Question

Why NotifyCollectionChangedEventArgs.NewItems Property is a list?

https://msdn.microsoft.com/en-us/library/system.collections.specialized.notifycollectionchangedeventargs.newitems(v=vs.110).aspx

From the above link, it says this property


Gets the list of new items involved in the change.


Since the collection only supports Add,Remove, Move for a single element, why this property returns a IList interface?

Answer

A collection type that implements this interface could have a method that adds multiple items in a single call, similar to the List<T>.AddRange(IEnumerable<T>) method.

The fact that ObservableCollection doesn't have such a method doesn't mean other collection types couldn't. However, ObservableCollection will always pass only 1 element (or null) to the NewItems collection of a NotifyCollectionChangedEventArgs.