小编use*_*512的帖子

使用linq检查ILookup <string,string>中的键是否存在值的最佳方法

  ILookup<string, string> someList;
            Cricket Sachin
                    Dravid
                    Dhoni
            Football Beckham
                     Ronaldo
                     Maradona
Run Code Online (Sandbox Code Playgroud)
bool status = someList.Where(x => x.Key == "Football").Where( y => y.Value == "Ronaldo") 
Run Code Online (Sandbox Code Playgroud)

应该回归真实

bool status = someList.Where(x => x.Key == "Football").Where( y => y.Value == "Venus williams")
Run Code Online (Sandbox Code Playgroud)

应该返回false

ILookup没有value属性,而不是循环,有没有更聪明的方法来获得几行结果.上面的代码是不对的,如果可能的话,希望有类似的东西.我是Linq的新手,所以学习更好的方法

c# linq linq-to-entities c#-4.0

6
推荐指数
2
解决办法
5274
查看次数

标签 统计

c# ×1

c#-4.0 ×1

linq ×1

linq-to-entities ×1