写“包含”使用 LINQ 查询
给定查询的输出:
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;
必须有一种更优雅的方法来计算结果。
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;
There must be an more elegant way to figure out the result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)