给定查询的输出:
var queryResult = from o in objects
where ...
select new
{
FileName = o.File,
Size = o.Size
}
您如何看待最新颖的方法来检测文件是否在queryResult中?
这是我对LINQ的la脚尝试:
string searchedFileName = "hello.txt";
var hitlist = from file in queryResult
where file.FileName == searchedFileName
select file;
var contains = hitlist.Count() > 0;
必须有一种更优雅的方法来计算结果。
最佳答案
string searchedFileName = "hello.txt";
var contains = queryResult.Any(file => file.FileName == searchedFileName);
关于c# - 使用LINQ编写 'CONTAINS'查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2379377/