There is this answer of a query
I am trying to understand what to put into this LINQ segment
pair => pair.Key, pair => pair.Value
My exact List definition is this:
List<Dictionary<string, StockDetails>> myList = new List<Dictionary<string, StockDetails>>();
This what I attempted but it got flagged for build errors:
IDictionary<string, StockDetails> dictionary = myList.ToDictionary(myList => myList.Key, pair => myList.Value);
As said, I am just trying to understand this LINQ part in how to properly define it for a successful build:
myList => myList.Key, pair => myList.Value);
My build errors are
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?)
Thanks for any help
myList
when it's already in scope) and tell us what you're trying to achieve. I thought you had a list of key/value pairs, but now you appear to have a list of dictionaries... – Greenroom