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

前端 未结 6 1245
南方客
南方客 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:11

    C#3:

    bool result = bar.Any(el => foo.Contains(el));
    

    C#4 parallel execution:

    bool result = bar.AsParallel().Any(el => foo.AsParallel().Contains(el));
    

提交回复
热议问题