【发布时间】:2011-01-17 14:34:37
【问题描述】:
SortedDictionary<int, string> typeDictionary = new SortedDictionary<int, string>();
SortedDictionary<int, int> lengthDictionary = new SortedDictionary<int, int>();
lengthDictionary 在键值对中的值如下:
<1,20>
<2,8>
<3,10>
<4,5>
我想要 LINQ 查询,它将返回如下新列表
<1,20>
<2,20+8=28> // 20 from key 1
<3,28+10=38> // 28 from key 2
<4,38+5=43> // 38 from key 3
结果应该是这样的:
<1,20>
<2,28>
<3,38>
<4,43>
【问题讨论】:
-
必须是 LINQ 吗?或者您只是对获得结果感到满意?
-
我仍然对
typeDictionary的来源感到非常困惑。一个简短但完整的示例确实会有所帮助 - 一如既往。 -
不要考虑 typeDictionary...
-
Linq 将优先考虑其他逻辑解决方案。
-
@User "不考虑 typeDictionary。" ...那么它不应该出现在您的问题中。
标签: c# sorting dictionary sum