Tuesday 15 September 2015

c# - Add an event function using linq -


I have a collection of classes and I want to add to the collection asset change event event.

When I try to use LINQ with this code to do this:

  (Select s from Straits VI. Property varies + = New contact switchage handler (message)). ToList ();   

I get an error:

  The type of expression in the selected section is incorrect. The type of estimation failed to 'select' to call    

LINQ < Em> query when you want to do something to , then this is not a query - it's all about the side effects, and you just get the normal Foreach should be used to apply the effects on the Linux collections - and in fact the side-effect is adopted by LINQ. I do not play well with lazy evaluation.

You just have a forehach loop:

  foreach (var s) in stratasavi {s.PropertyChanged + = Messege; } I also suggest that you read Eric Lipert's blog post, which discusses philosophical differences between statements and expressions.  

Note that if you wanted actually you wanted that you still use LINQ with a statement statement after a statement body and event subscription ... but this To some extent, LINQ will be distorted that I do not even want to include it in response even list & lt; T & gt; By using any. there will be an improvement on it.

No comments:

Post a Comment