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

后端 未结 8 702
遇见更好的自我
遇见更好的自我 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:52

    If you didn't care about performance, you could try:

    a.Any(item => b.Contains(item))
    // or, as in the column using a method group
    a.Any(b.Contains)
    

    But I would try this first:

    a.Intersect(b).Any()
    

提交回复
热议问题