gpt4 book ai didi

c# - 为什么 NotifyCollectionChangedEventArgs.NewItems 属性是一个列表?

转载 作者:行者123 更新时间:2023-11-30 23:19:38 26 4
gpt4 key购买 nike

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

从上面的链接,它说这个属性

Gets the list of new items involved in the change.

既然集合只支持单个元素的Add、Remove、Move,为什么这个属性返回的是IList接口(interface)?

最佳答案

实现此接口(interface)的集合类型可以有一个在单个调用中添加多个项目的方法,类似于 List<T>.AddRange(IEnumerable<T>) 方法。

事实ObservableCollection没有这样的方法并不意味着其他集合类型不能。然而,ObservableCollection将始终仅将 1 个元素(或 null )传递给 NewItems NotifyCollectionChangedEventArgs 的集合。

关于c# - 为什么 NotifyCollectionChangedEventArgs.NewItems 属性是一个列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40168783/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com