检查数组中的字符串是否出现在LINQ中的另一个字符串数组中?

jaf*_*ffa 1 linq

这应该很简单,但LINQ的Contains()不接受数组.我有2个字符串数组

eg1 {"The","quick","Brown"}

我想比较另一个字符串数组,如果出现任何字符串,则返回true.

eg2 {"This","doesnt","quick","Work"}

所以"快速"出现在第二个阵列中.

是否最好使第一个字符串加入逗号分隔,因此它看起来像"The,quick,Brown"然后运行包含在一个循环中对它?

我确信这可以使用LINQ正确完成.

Luk*_*keH 6

bool exists = first.Intersect(second).Any();
Run Code Online (Sandbox Code Playgroud)

或者,如果你想知道常见词是什么:

var commonWords = first.Intersect(second);

foreach (string s in commonWords)
{
    Console.WriteLine(s);
}
Run Code Online (Sandbox Code Playgroud)