代码之家  ›  专栏  ›  技术社区  ›  Podge

Linq和字典以及转换数组值

  •  4
  • Podge  · 技术社区  · 15 年前

    IDictionary<string, IEnumerable<Control>>
    

    我需要把它转换成

    IDictionary<string, IEnumerable<string>>
    

    有人知道如何在Linq中实现这一点而不是遍历字典吗?

    谢谢

    2 回复  |  直到 15 年前
        1
  •  4
  •   flq    15 年前

    如果没有一个手工编译器,像这样的东西应该可以工作。。。

    dictOne
      .ToDictionary(k=>k.Key, v=>v.Value.Select(c=>c.ClientID))
    
        2
  •  6
  •   Matthew Abbott    15 年前

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