Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq and Dictionary and converting array values

Tags:

c#

linq

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

like image 391
Podge Avatar asked Dec 28 '22 09:12

Podge


1 Answers

Something like

IDictionary<string, IEnumerable<Control>> input = ...
IDictionary<string, IEnumerable<string>> output = 
    input.ToDictionary(item => item.Key,
                       item => item.Value.Select(control => control.ClientID)); 
like image 168
marcind Avatar answered Jan 05 '23 01:01

marcind