Linq and Dictionary and converting array values
I have the following code
IDictionary<string, IEnumerable<Control>>
开发者_Python百科
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
Something like
IDictionary<string, IEnumerable<Control>> input = ...
IDictionary<string, IEnumerable<string>> output =
input.ToDictionary(item => item.Key,
item => item.Value.Select(control => control.ClientID));
Without having a compiler by hand, something like this should work...
dictOne
.ToDictionary(k=>k.Key, v=>v.Value.Select(c=>c.ClientID))
精彩评论