【发布时间】:2010-12-07 17:06:12
【问题描述】:
我有以下 XML,当您通过特定统计时,我需要一个查询来提取年份和 Return_Value。
当前代码不起作用,因为在一个字典对象的 add 语句中不能有两个 where 子句。这个问题有方法解决吗?
foreach (var row in rows)
{
myHoldingsDistribution.Add(row.Descendants()
.Where(y => y.Name.LocalName == keyName)
.Select(q => q.Value).Max(),
Double.Parse(row.Descendants().Where(y => y.Name.LocalName == valueName)
.Select(q => q.Value).Max()) * multiplier);
<Table>
<Year>1</Year>
<Statistic>0 Percentile</Statistic>
<Return_Value>0.0535644000000</Return_Value>
</Table>
base {System.Xml.Linq.XContainer}: <Table>
<ALMRunResults_Year>1</ALMRunResults_Year>
<Statistic>0 Percentile</Statistic>
<Return_Value>0.0535644000000</Return_Value>
</Table>
FirstAttribute: null
HasAttributes: false
HasElements: true
IsEmpty: false
LastAttribute: null
Name: {Table}
NodeType: Element
Value: "10 Percentile0.0535644000000"
编辑
在下面的语句中 - 理想情况下,我希望 .where 两次过滤掉那些不是 1 Percentile 的。
myHoldingsDistribution.Add(row.Descendants()
.Where(y => y.Name.LocalName == keyName)
.Select(q => q.Value).Max(),
Double.Parse(row.Descendants().Where(y => y.Name.LocalName == valueName)
.Select(q => q.Value).Max()) * multiplier);
【问题讨论】:
-
“你不能有两个 where 子句”是什么意思?您从提供的代码中得到什么错误?
-
“理想情况下,我希望 .where 两次过滤掉那些不是 1 Percentile 的。” ——是什么阻止了你?您通常可以将 .Where 语句链接在一起:
rows.Where(...).Where(...)当您尝试此操作时会发生什么,代码是什么样的?
标签: xml linq silverlight dictionary