给出查询的输出:
var queryResult = from o in objects
where ...
select new
{
FileName = o.File,
Size = o.Size
}
您认为检测文件是否在queryResult中的最佳方法是什么? 这是我对LINQ的蹩脚尝试:
string searchedFileName = "hello.txt";
var hitlist = from file in queryResult
where file.FileName == searchedFileName
select file;
var contains = hitlist.Count() > 0;
必须有更优雅的方法来确定结果。
答案 0 :(得分:17)
string searchedFileName = "hello.txt";
var contains = queryResult.Any(file => file.FileName == searchedFileName);