Concerning speed: List<T> will always be faster, just because ObservableCollection<T> derives from Collection<T> and the items of Collection<T> are stored in a List<T>, see the "items" field / Member of Collection<T>.
So it will never be faster as a List<T> but always put some overhead to its operations.
Most noticeable is the overhead that comes from the CollectionChanged listeners.
Since Eventhandlers are invoked synchronously most of the time in .NET, all Add/Remove/Clear/Insert/Move ops can be some 10-100 times slower with an observable collection since the listener can execute any kind of code in the event handler. Of course the publishing / mult-casting of the event takes some time itself.
If you don't need to observe collection changes, using an ObservableCollection is just a bad idea. Despite of speed you loose convenience - an ObservableCollection has no AddRange, InsertRange, RemoveRange, ForEach, Sort, Find*, FindLast* methods just to mention a view.
Chris
No comments:
Post a Comment