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

前端 未结 6 1258
南方客
南方客 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 07:58

    Another solution:

    var result = array1.Any(l2 => array2.Contains(l2)) == true ? "its there": "not there";
    

    If you have class instead of built in datatypes like int etc, then need to override Override Equals and GetHashCode implementation for your class.

提交回复
热议问题