LINQ How to force query to materialize?

Posted by Bobb on Stack Overflow See other posts from Stack Overflow or by Bobb
Published on 2010-06-16T22:45:55Z Indexed on 2010/06/16 22:52 UTC
Read the original article Hit count: 176

Filed under:
|

Say I have simple LINQ extenstion:

var filtered = data.Where(i => i.Count > 0);

I know that this will not evaluated unless I start to use filtered i.e.

foreach(DataItem i in filtered) ...

However I need to create cloned version of data and release data as soon as possible. data can be changed in other thread so I want to get immediate snapshot of it.

How can I force filtered to be evaluated immediately?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ