why does an event handler never gets called if its added within a loop on an ienumerable
- by André Carvalho
For instance:
IEnumerable<MyType> list = someCollection.Select(i => new MyType(i));
foreach (var item in list)
item.PropertyChanged += item_PropertyChanged; <-- this never gets called
Bu if list is assigned like
list = someCollection.Select(i => new MyType(i)).ToArray();
the event handler does get called..
Why? (i imagine it has something to do with the fact that a linq query is lazy, but the fact of looping through the result isn't enough??)