How to find if an element of a list is in another list?

前端 未结 5 487
误落风尘
误落风尘 2020-12-29 04:43

I want to know if at least one element in a first list can be found in a second list.

I can see two ways to do it. Let\'s say our lists are:

List<         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 05:10

    The accepted answer is great, however it does not work with Linq-to-sql, since there's no mapping for Intersect. In that case you should use :

    bool isFound = table.Any(row => list2.Contains(row.FieldWithValue));
    

    This gets compiled to WHERE EXSITS

提交回复
热议问题