1

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,

  1. outer dictionary.Values.Select(x=> x.Values)
  2. foreach loop

The problem with first solution is that it won't give only objects and second solution is time consuming.

Pavan
  • 337
  • 5
  • 23

1 Answers1

1

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)) {
    ...
}
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523