tags:

views:

63

answers:

2

Hello, I have the following code

IDictionary<string, IEnumerable<Control>>

I need to convert it to

IDictionary<string, IEnumerable<string>>

using ClientID as the new value.

Does anybody know how to do this in Linq instead iterating through the dictionary?

Thanks

Podge

+5  A: 

Something like

IDictionary<string, IEnumerable<Control>> input = ...
IDictionary<string, IEnumerable<string>> output = 
    input.ToDictionary(item => item.Key,
                       item => item.Value.Select(control => control.ClientID)); 
marcind
+4  A: 

Without having a compiler by hand, something like this should work...

dictOne
  .ToDictionary(k=>k.Key, v=>v.Value.Select(c=>c.ClientID))
flq
Thanks very much. I couldn't see the wood for the trees. I was thinking I would have to use SelectMany.
Podge