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

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

    You can check if a list is inside of another list with this

    var list1 = new List { 1, 2, 3, 4, 6 };
    var list2 = new List { 2, 3 };
    bool a = list1.Any(c => list2.Contains(c));
    

提交回复
热议问题