How to check if an array contains any item of another array

前端 未结 6 1351
南方客
南方客 2021-01-31 07:35

Given 2 int arrays e.g, foo and bar, what\'s the most efficient way to check that the array bar contains at least one item that foo contains. should re

6条回答
  •  情书的邮戳
    2021-01-31 08:05

    Using LINQ:

    array1.Intersect(array2).Any()
    

    Note: Using Any() assures that the intersection algorithm stops when the first equal object is found.

提交回复
热议问题