Click here to Skip to main content
15,941,755 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem, I'm trying to get from my dictionary :
new Dictionary<Dictionary<MapMember, List<long>>, double>();
List<long> so that I can pass the list in foreach.How do I get individual long values?

What I have tried:

To illustrate,
Dictionary<Dictionary<MapMember, List<long>>, double>()
has four values, then each
Dictionary<MapMember, List<long>
has one key and several values ​​in List
Updated 17-Oct-22 1:34am

This website is great for beginners and those needing a reference: tutorialsteacher - C# Dictionary[^]
Share this answer
You can extract the values by looping over the keys of the outer dictionary, then looping over the values of the inner dictionary:
foreach (Dictionary<MapMember, List<long>> key in yourDictionary.Keys)
    foreach (List<long> list in key.Values)
        // Do something with the list here...

However, using a Dictionary as the key for another Dictionary is almost certainly the wrong thing to do.
Share this answer
dejf111 17-Oct-22 7:24am    
And how should it be done? That is, with the same function.
Richard Deeming 17-Oct-22 7:49am    
No idea, since you haven't told us what you're actually trying to do, only that you have a dictionary which uses a dictionary as its key.
Dave Kreskowiak 17-Oct-22 8:27am    
What your code said was NOT "use this value from this inner dictionary as the key in the outer dictionary." Your code said "use the ENTIRE INNER DICTIONARY OBJECT as the key to the outer dictionary."

It looks like you should be using two independent dictionaries, but since you haven't said anything about the data you're trying to represent and their relations, it's impossible for anyone to tell you what to do to fix this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900