Thursday, February 18, 2010

evaluation of LINQ expression using .ToArray()

IEnumerable windowsFiles = System.IO.Directory.GetFiles(Environment.GetEnvironmentVariable("SystemRoot"), "*.INF", System.IO.SearchOption.AllDirectories);

IEnumerable files =
(
from f in windowsFiles
where System.IO.File.ReadAllText(f).Contains(searchText)
select System.IO.Path.GetFileNameWithoutExtension(f)
).ToArray(); // ToArray forces immediate evaluation.

No comments: