开发者

Linq and Dictionary and converting array values

开发者 https://www.devze.com 2023-01-10 08:12 出处:网络
I have the following code IDictionary<string, IEnumerable<Control>> 开发者_Python百科 I need to convert it to

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))
0

精彩评论

暂无评论...
验证码 换一张
取 消