【发布时间】:2017-09-30 17:37:01
【问题描述】:
给定以下数据源:
public struct Strc
{
public decimal A;
public decimal B;
// more stuff
}
public class CLASS
{
public List<Strc> listStrc = new List<Strc>();
// other stuff
}
Dictionary<string, CLASS> dict = new Dictionary<string, CLASS>();
我需要收集字典中的所有Strc.B,前提是Strc.A是例如> 3。
我得到了以下结果:
List<decimal> results = (
from v in dizS.Values
from ls in v.listStr
where ls.A > 3
select ls.B
).ToList();
我也尝试使用 lambdas 编写它,但我失败得很惨……
var res = dict.Values.Where(x => x.listStrc.Any(z => z.A > 3))
这是我所能得到的,但我没有设法选择 .B 数据...... 我做错了什么? (鉴于我一开始就做对了:D) 感谢您的宝贵时间。
【问题讨论】:
-
您的查询表达式应该是您想要的。我不明白你的问题是什么?
-
嗨,没有 lambdas 的工作正常,我无法让有 lambdas 的工作。