ObservableCollection(IEnumerable) 构造函数的行为
根据 MSDN,ObservableCollection 构造函数有一个重载,您可以向其传递 IEnumerable。根据非常短的 MSDN 页面,这将制作 Ienumerable 的“副本”。
我如何确定它的行为方式? “副本”是否完全独立于原始版本,或者对 Ienumerable 所做的更改(例如通过 linq 查询)是否会自动反映在 ObservableCollection 中?
According to MSDN there is an overload for the ObservableCollection constructor to which you can pass an IEnumerable. According to the very short MSDN page this will make a "Copy" of the Ienumerable.
How do I determine how this will behave? Will the "Copy" be totally independent of the original or will changes made to the Ienumerable (Such as by a linq query) be reflected automatically in the ObservableCollection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此构造函数遍历
IEnumerable
中的项目,并将每一项添加到ObservableCollection
中。完成此操作后,新的ObservableCollection
与IEnumerable
不再有任何关系(除非您正在处理引用类型的集合,则ObservableCollection
code> 将保存对IEnumerable
提供的相同对象的引用。This constructor walks through the items in the
IEnumerable
and adds each one to theObservableCollection
. Once this is finished the newObservableCollection
has nothing more to do with theIEnumerable
(except that if you are dealing with a collection of reference types then theObservableCollection
will hold references to the same objects that were supplied by theIEnumerable
).