有一个问题的答案
我试图理解应该在这个LINQ段中放入什么内容
pair => pair.Key, pair => pair.Value
我的清单定义如下:
List<Dictionary<string, StockDetails>> myList = new List<Dictionary<string, StockDetails>>();
我尝试了以下代码,但由于构建错误而被标记:
IDictionary<string, StockDetails> dictionary = myList.ToDictionary(myList => myList.Key, pair => myList.Value);
就像之前所说的,我只是想了解如何正确定义 LINQ 部分以便成功构建的问题:
myList => myList.Key, pair => myList.Value);
我的构建错误如下:
Error 7 'System.Collections.Generic.Dictionary<string,xx.Models.StockDetails>' does not contain a definition for 'Key' and no extension method 'Key' accepting a first argument of type 'System.Collections.Generic.Dictionary<string,xx.Models.StockTickerDetails>' could be found (are you missing a using directive or an assembly reference?)
xxxx
Error 9 'System.Collections.Generic.List<System.Collections.Generic.Dictionary<string,xx.Models.StockTickerDetails>>' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'System.Collections.Generic.List<System.Collections.Generic.Dictionary<string,xx.Models.StockDetails>>'
could be found (are you missing a using directive or an assembly reference?)
感谢您的帮助。
myList
)并告诉我们您想要实现什么。我以为你有一个键/值对列表,但现在你似乎有一个字典列表... - Jon Skeet