Pros and Cons of using Observable Collection over IEnumerable

后端 未结 4 1330
轮回少年
轮回少年 2020-12-18 07:42

I am trying to decide if I want to switch all of my IEnumerable collections over to Observable Collections. I cannot find a good explanation of this. What are t

4条回答
  •  时光说笑
    2020-12-18 08:27

    The largest benefit to using ObservableCollection is it implements INotifyCollectionChanged and INotifyPropertyChanged, automatically, which makes it simpler to data-bind. I would say that it's better to use ObservableCollection when you are first setting up your data-bindings.

    But now that you have already coded up (and data-bound?) a bunch of IEnumerables, there isn't any savings to be had, at this point.

    Another thing to consider is that ObservableCollection is an IEnumerable (Inherited from Collection). Since IEnumerable is an interface, it is implemented by many classes List is one such class - ObservableCollection is another.

提交回复
热议问题