检查数组包含另一个数组任何项目 [英] check if an array contains any item from another array
本文介绍了检查数组包含另一个数组任何项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于2 INT阵列如foo和酒吧,有什么检查数组栏包含至少一个项目是富包含最有效的方式。应该返回真/假。
Given 2 int arrays eg, foo and bar, what's the most efficient way to check that the array bar contains at least one item that foo contains. should return true/false.
IM怀疑嵌套的foreach,但只是想知道如果theres一个更好的方式。
im suspecting nested foreach but just wondering if theres a nicer way.
推荐答案
使用LINQ:
array1.Intersect(array2).Any()
这篇关于检查数组包含另一个数组任何项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文