Initialize ObservableCollection C# with Example
ObservableCollection is a collection of type T like List which means that it holds objects of type T.
From documentation we read that :
ObservableCollectionrepresents a dynamic data collection that provides notiﬁcations when items get
added, removed, or when the entire list is refreshed.
The key diﬀerence from other collections is that ObservableCollection implements the interfaces
INotifyCollectionChanged and INotifyPropertyChanged and immediately raise notiﬁcation event when a new
object is added or removed and when collection is cleared.
This is especially useful for conneting the UI and backend of an application without having to write extra code
because when an object is added to or removed from an observable collection, the UI is automatically updated.
The ﬁrst step in order to use it is to include
You can either create an empty instance of a collection for example of type string
ObservableCollection collection = new ObservableCollection();
or an instance that is ﬁlled with data
ObservableCollection collection = new ObservableCollection()
Remember as in all IList collection, index starts from 0 (IList.Item Property).