Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does List<string> have a Changed event in c#?

Tags:

c#

I have recently bought a book called "The c# programming language" 4th edition. On page 49 there is a reference to a List having a changed event that can be bound to as an example of events. Have tried to reproduce this but ended up doing some head scratching with this :-

List<string> names = new List<string>();
names.Changed+= new EventHandler(ListChanged);

and so it continues.... Am I missing something or does List not have a changed event?

like image 821
Sali Avatar asked Dec 16 '22 08:12

Sali


1 Answers

No, List<T> doesn't have such event, you are not missing anything. You may checkout the ObservableCollection<T> which has a CollectionChanged event you could subscribe to. It is extensively used in WPF and Silverlight to implement the MVVM pattern.

like image 150
Darin Dimitrov Avatar answered Dec 31 '22 20:12

Darin Dimitrov