c# – Lambda表达式循环遍历两个并发字典

我试图循环两个并发的字典,如下面的代码,但我想使用lambda表达式

       foreach (var s in sb_eventdata)
        {  
            foreach (var f in final_data)
            {
                 if (s.Value.Car.Equals(f.Value.Car))
                 {
                      Console.Writeline("Found!");
                 }
            }
       }

var values = sb_eventdata.Where(k => k.Value.Hometeam.Contains(????);

我真的不确定要传入包含什么,我假设另一个lambda表达式但是什么?

最佳答案 与循环最接近的linq表达式为:

var sb_eventdata = new Dictionary<string, string>{ {"a", "a"}, {"b", "b"}};
var final_data = new Dictionary<string, string>{{"a", "a"}, {"b", "b"}, {"c","c"}};

var result = 
    // first loop
    sb_eventdata.Select(s => 
        // second loop
        final_data.Where(f => s.Value.Equals(f.Value)))
    // flatten results (returns results from the first dictionary)
    .SelectMany(x => x);
点赞