Is there a C# IN operator?

后端 未结 14 1875
说谎
说谎 2020-12-08 03:51

In SQL, you can use the following syntax:

SELECT *
FROM MY_TABLE
WHERE VALUE_1 IN (1, 2, 3)

Is there an equivalent in C#? The IDE seems to

14条回答
  •  悲&欢浪女
    2020-12-08 04:28

    The in keyword in C# is for the foreach statement and for LINQ query expressions. There is no functionality equivalent to SQL's in operator in C# per se, but LINQ offers similar functionality with Contains().

    var list = {1, 2, 3}
    var filtered = (
        from item in items
        where list.Contains(item)
        select item).ToArray().
    

提交回复
热议问题