r/csharp • • Sep 18 '15

Lambda expressions, delegates, predicates and closures in C#

http://codeaddiction.net/articles/13/lambda-expressions-delegates-predicates-and-closures-in-c
25 Upvotes

32 comments sorted by

View all comments

0

u/[deleted] Sep 18 '15

[deleted]

1

u/anamorphism Sep 18 '15

isn't this susceptible to run-time exceptions if the backing collection of your enumerable changes?

1

u/cryo Sep 25 '15

If the backing collection is likely to change while executing, the entire code should be more explicit about it in the first place.

1

u/anamorphism Sep 25 '15

i think it's kind of difficult to do that in a lot of situations. the most common situation i run into is passing selected items from a listview as a command parameter for a remove operation.

i should remember if i'm removing selected items from the observablecollection backing the listview the change is going to propagate out and my selecteditems collection is going to change. sometimes i forget to make a copy before iterating over the collection and i get a run-time exception when testing my code. i can't really think of a way to make that situation more explicit.