有没有办法从 ObservableCollection 获取范围?
我想从 ObservableCollection 中获取一个范围,以便循环遍历它并更改这些项目的属性。是否有一种简单的内置方法可以使用 ObservableCollection 类来执行此操作?
I would like to get a range from an ObservableCollection for the purpose of looping through it and changing a property on those items. Is there an easy built-in way to do this with the ObservableCollection class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
Skip
和Take
。You can use
Skip
andTake
.对于循环,
ObservableCollection
派生来自Collection
,并实现IList
。这允许您按索引循环:如果您想通过 LINQ 对集合进行查询,您有几个选择。您可以使用 Skip() 和 Take(),或构建新范围并按索引访问:
或者:
For looping,
ObservableCollection<T>
derives fromCollection<T>
, and implementsIList<T>
. This lets you loop by index:If you want to do queries on the collection via LINQ, you have a couple of options. You can use Skip() and Take(), or build a new range and access by index:
Or:
ObservableCollection
实现Collection
,它实现IEnumerable
所以你应该能够做到(如果你正在寻找一个范围)匹配给定条件):或任意范围(在本例中需要项目 10 - 40):
ObservableCollection<T>
implementsColletion<T>
which implementsIEnumerable
so you should be able to do (if you're looking for a range that matches a given criteria):Or an arbitrary range (in this case it takes items 10 - 40):
跳过和Take 是用于对集合进行分页的 linq 扩展方法。
Skip and Take are linq extension methods used for paging a collection.