I have a nested concurrent dictionary as given below:
ConcurrentDictionary<string,ConcurrentDictionary<string,<Class Object>>>
I want to get all objects (values of inner dictionary) into list for further processing without knowing any key.
I tried below two solutions but it does not work for me,
dictionary.Values.Select(x=> x.Values)
foreach
loop The problem with first solution is that it won't give only objects and second solution is time consuming.
If you run dictionary.Values.Select(x=> x.Values)
you would not get a list of object values from the inner dictionaries; you will get a list of lists of object values.
To "flatten" that list, use SelectMany
:
foreach (var inner in dictionary.Values.SelectMany(x=> x.Values)) {
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.