在集合上带有“where in”子句的Linq

在集合上带有“where in”子句的Linq,linq,Linq,我有两张清单[收藏] 例如: ListA有100个字符串键 ListB有50个字符串键 现在我想在ListA上写一个linq查询,在这里我想找到ListB中的公共键 请帮助举个例子: //Define 2 Lists var ListA = new List<string>(); var ListB = new List<string>(); for(int i = 0; i < 100; i++) { //if counter smaller 50 ad

我有两张清单[收藏]

例如:

ListA有100个字符串键 ListB有50个字符串键 现在我想在ListA上写一个linq查询,在这里我想找到ListB中的公共键

请帮助

举个例子:

//Define 2 Lists
var ListA = new List<string>();
var ListB = new List<string>();

for(int i = 0; i < 100; i++)
{
    //if counter smaller 50 add to both lists
    if(i < 50)
    {
        ListA.Add("Value"+i);
        ListB.Add("Value"+i);
    }
    //add only to listA 
    else
        ListA.Add("Value"+i);
}
//ListA ranges from 0 to 99
//ListB ranges from 0 to 49
var result = ListA.Intersect(ListB);
结果的输出将是一个IEnumerable,其值范围为Value0到Value49,因为这两个列表中都有键。

l1.l2。已经有很多问题了。进行搜索。