复杂的 LINQ 查询
考虑到这种结构...
List<IEnumerable<KeyValuePair<String, String>>>
您将如何为以下伪代码编写 LINQ 查询...
SELECT
/* Count of how many [KeyValuePair] exists in [List] */
FROM
[List]
WHERE
[KeyValuePair].Key == "foo"
AND Int32.Parse([KeyValuePair].Value.Replace(".", "")) > 10
...?
更新
上述查询的结果,根据下面的列表运行,应该是 6(六)...
var list = new List<IEnumerable<KeyValuePair<String, String>>>
{
new []
{
new KeyValuePair<String, String>("foo", "1.1"),
new KeyValuePair<String, String>("foo", "1.2"),
new KeyValuePair<String, String>("foo", "1.3")
},
new []
{
new KeyValuePair<String, String>("foo", "0.1"),
new KeyValuePair<String, String>("foo", "0.2"),
new KeyValuePair<String, String>("foo", "0.3")
},
new []
{
new KeyValuePair<String, String>("foo", "2.1"),
new KeyValuePair<String, String>("foo", "2.2"),
new KeyValuePair<String, String>("foo", "2.3")
}
};
Considering this structure...
List<IEnumerable<KeyValuePair<String, String>>>
How would you write a LINQ query for the following pseudo-code...
SELECT
/* Count of how many [KeyValuePair] exists in [List] */
FROM
[List]
WHERE
[KeyValuePair].Key == "foo"
AND Int32.Parse([KeyValuePair].Value.Replace(".", "")) > 10
...?
Update
The result of the above query, run aginst the list below, should be 6 (six)...
var list = new List<IEnumerable<KeyValuePair<String, String>>>
{
new []
{
new KeyValuePair<String, String>("foo", "1.1"),
new KeyValuePair<String, String>("foo", "1.2"),
new KeyValuePair<String, String>("foo", "1.3")
},
new []
{
new KeyValuePair<String, String>("foo", "0.1"),
new KeyValuePair<String, String>("foo", "0.2"),
new KeyValuePair<String, String>("foo", "0.3")
},
new []
{
new KeyValuePair<String, String>("foo", "2.1"),
new KeyValuePair<String, String>("foo", "2.2"),
new KeyValuePair<String, String>("foo", "2.3")
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从中得到6分...
I get 6 from this...
虽然我猜你正在替换“。”因为您想摆脱千位分隔符,所以您可能需要:Int32.Parse(item.Value, NumberStyles.AllowThousands, CultureInfo.CurrentCulture)
确保正确设置了当前区域性。 Strike>为了清楚起见,我可能会这样写:
理解语法可能如下所示:
Although I'm guessing you're replacing the "." because you want to get rid of thousands separators, so You might want:Int32.Parse(item.Value, NumberStyles.AllowThousands, CultureInfo.CurrentCulture)
making sure you have the Current Culture set appropriately.I might write it for clarity like this:
Comprehension syntax might look like: