开发者

Writing 'CONTAINS' query using LINQ

Given the output of query:

var queryResult = from o in objects
                  where ...
                  select new 
                      {
                         FileName = o.File,
                         Size = o.Size
                      }

What would you consider the neatest way to detect if a file is in the queryResult? Here is my lame try with LINQ:

string searchedFileName = "hello.txt";
var hitlist = from file in queryResult
              where file.FileName == searchedFileName
              select file;
var contains = hitlist.Count() > 0;

Ther开发者_Go百科e must be an more elegant way to figure out the result.


string searchedFileName = "hello.txt";
var contains = queryResult.Any(file => file.FileName == searchedFileName);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜