What is the use of ObservableCollection in .net?
C# – the use of ObservableCollection in .net
cnetobservablecollection
Related Topic
- C# – How to enumerate an enum
- C# – What are the correct version numbers for C#
- .net – the best algorithm for overriding GetHashCode
- C# – How to get a consistent byte representation of strings in C# without manually specifying an encoding
- C# – Proper use of the IDisposable interface
- .net – Difference between decimal, float and double in .NET
- .net – the difference between .NET Core and .NET Standard Class Library project types
Best Answer
ObservableCollection is a collection that allows code outside the collection be aware of when changes to the collection (add, move, remove) occur. It is used heavily in WPF and Silverlight but its use is not limited to there. Code can add event handlers to see when the collection has changed and then react through the event handler to do some additional processing. This may be changing a UI or performing some other operation.
The code below doesn't really do anything but demonstrates how you'd attach a handler in a class and then use the event args to react in some way to the changes. WPF already has many operations like refreshing the UI built in so you get them for free when using ObservableCollections