Get a Join on Two Dictionaries with different Datatypes in C#

后端 未结 2 908
走了就别回头了
走了就别回头了 2021-01-14 08:43

I have two dictionaries, namely

Dictionary DictA=new Dictionary();
Dictionary DictB=new Dictiona         


        
2条回答
  •  借酒劲吻你
    2021-01-14 09:20

    Very simple:

    var query =
        DictA
            .Where(a => DictB.ContainsKey(a.Key))
            .ToDictionary(a => DictB[a.Key], a => a.Value);
    

    I get this result:

    result

提交回复
热议问题