How to check list A contains any value from list B?

后端 未结 8 689
遇见更好的自我
遇见更好的自我 2021-01-30 08:04

List A:

1, 2, 3, 4

List B:

2, 5

How to check if list A contains any value from list B?

e.g. someth

8条回答
  •  失恋的感觉
    2021-01-30 08:47

    For faster and short solution you can use HashSet instead of List.

    a.Overlaps(b);
    

    Overlaps documentation

    This method is an O(n) instead of O(n^2) with two lists.

提交回复
热议问题