How do you implement the equivalent of SQL IN() using .net

前端 未结 9 1484
春和景丽
春和景丽 2020-12-09 16:24

In .net (c# or vb) expressions, how would you implement SQL\'s handy IN() functionality?

i.e. value in (1, 2, 4, 7)

rather than:

value = 1 or value =

9条回答
  •  爱一瞬间的悲伤
    2020-12-09 16:38

    If you will do many lookups on the same dataset it is good from a performance perspective to use HashSet.

    HashSet numbers = new HashSet { 1, 2, 4, 7 };
    bool is5inSet = numbers.Contains(5);
    

提交回复
热议问题