seb*_*mez 1 c# linq intersection
我有两个数组,我知道最简单的方法是知道它们是否有共同的元素.所以实际上这个问题不得不提问.
string[] countries1 = new string[] { "USA", "Uruguay", "India", "UK"};
string[] countries2 = new string[] { "Urguay", "Argentina", "Brasil", "Chile" };
foreach (string country in countries1)
if (countries2.Contains(country))
return true;
return false;
Run Code Online (Sandbox Code Playgroud)
country1国家/地区也在country2阵列中,它会让我知道? 1) var isIntersection = countries1.Intersect(countries2).Any();
2) var intersectedCountries = countries1.Intersect(countries2);