LINQ:我可以从集合中列表中的对象获取属性吗?
foreach (ReportType t in reportsCollection)
{
List<Report> reps = (from r in t.reports where r.isChecked == true select r).ToList<Report>();
foreach (Report r in reps)
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(r.path));
}
这个声明效果很好。我只是在寻找一个可以做到这一点的 LINQ 语句。
基本上,我有一个带有名为 isChecked 属性的报告对象。 reportsCollection 包含多个reportTypes,其中包含该类型的报告列表。所以集合看起来像这样:
type1
- 报告
- 报告 2
- 报告 3
类型 2
- 报告 4
- 报告 5
- 报告 6
等等。
我想要一个 LINQ 语句来获取这些类型中 isChecked == true
的所有报告。我怀疑循环是必要的,但我很好奇社区是否有解决方案。谢谢!
foreach (ReportType t in reportsCollection)
{
List<Report> reps = (from r in t.reports where r.isChecked == true select r).ToList<Report>();
foreach (Report r in reps)
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(r.path));
}
This statement works just fine. I'm just looking for a single LINQ statement that could maybe do this.
Basically, I have a report object with a property called isChecked. reportsCollection contains several reportTypes that contains lists of reports of that type. So the collection looks like this:
type1
- report
- report 2
- report 3
type 2
- report 4
- report 5
- report 6
and so on.
I want a LINQ statement that will grab all reports where isChecked == true
within those types. I suspect a loop is necessary, but I was curious to see if the community had a solution. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想使用 SelectMany
查询表达式语法形式,您可以将其写为
You want to use SelectMany
In query expression syntax form, you might write it as
在查询语法中,它看起来像这样
In query syntax it will look like this