的ObservableCollection<> VS列表与LT;> [英] ObservableCollection<> vs List<>

查看:190
本文介绍了的ObservableCollection<> VS列表与LT;>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多的实体嵌​​套名单,其中;> 中的每个

I have lots of entities with nested List<> in each

例如,我有BaseEntity有名单,其中,ColumnEntity&GT; Col​​umnEntity 类有名单,其中,信息&gt;

For example i have BaseEntity which has List<ColumnEntity> ColumnEntity class has List<Info> and so on.

我们正在与WPF界面,我们需要跟踪BaseEntity的每一个列表中的所有变化。现在,它是与创建新的ObservableCollection 根据需要的名单,并绑定到的ObservableCollection实现的。

We are working with WPF UI, and we need to track all changes in every List of BaseEntity. Now it is implemented with creating new ObservableCollection based on needed list, and with binding to that ObservableCollection.

你能说出优劣改变这一切的嵌套列表来ObservableCollections? 因此,我们可以跟踪BaseEntity本身的所有更改,但不重新分配BaseEntity的每个列表来修改绑定的ObservableCollection?

Can you name pros and cons changing all this nested Lists to ObservableCollections? So we can track all changes in BaseEntity itself without reassigning each list of BaseEntity to modified bound ObservableCollection?

假设具体列出所有的方法都从未使用过。

Assuming that all methods specific to List are never used.

推荐答案

有趣的问题,考虑到这两个列表和的ObservableCollection 实施的IList&LT; T&GT; 没有多大的差别存在,的ObservableCollection 也农具 INotifyCollectionChanged 接口,哪允许WPF绑定到它。

Interesting question, considering that both List and ObservableCollection implement IList<T> there isn't much of a difference there, ObservableCollection also implements INotifyCollectionChanged interface, which allows WPF to bind to it.

其中一个主要的区别是,的ObservableCollection 没有的AddRange 的方法,这可能有一定的影响。

One of the main differences is that ObservableCollection does not have AddRange method, which might have some implications.

我也不会用的ObservableCollection 的,我知道我不会被绑定,基于这个原因,重要的是去了你的设计,并确保你的地方正在采取正确的方法在分离关注的层。

Also I would not use ObservableCollection for places where I know I would not be binding to, for this reason it is important to go over your design and making sure that you are taking the correct approach in separating layers of concern.

收藏℃之间的差异; T&GT; 名单,其中,T&GT; ,你可以看看这里 泛型列表VS系列

As far as the differences between Collection<T> and List<T> you can have a look here Generic Lists vs Collection

这篇关于的ObservableCollection&LT;&GT; VS列表与LT;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆