在SQL中,您可以使用以下语法:
SELECT *
FROM MY_TABLE
WHERE VALUE_1 IN (1, 2, 3)
Run Code Online (Sandbox Code Playgroud)
C#中有等价物吗?IDE似乎将"in"识别为关键字,但我似乎无法在其上找到任何信息.
那么,是否可以执行以下操作:
int myValue = 1;
if (myValue in (1, 2, 3))
// Do something
Run Code Online (Sandbox Code Playgroud)
代替
int myValue = 1;
if (myValue == 1 || myValue == 2 || myValue == 3)
// Do something
Run Code Online (Sandbox Code Playgroud) 在我的代码中,我经常需要将变量与几个值进行比较:
if ( type == BillType.Bill || type == BillType.Payment || type == BillType.Receipt )
{
// Do stuff
}
Run Code Online (Sandbox Code Playgroud)
我一直在想我能做到:
if ( type in ( BillType.Bill, BillType.Payment, BillType.Receipt ) )
{
// Do stuff
}
Run Code Online (Sandbox Code Playgroud)
但当然那是允许这种情况的SQL.
C#中有更整洁的方式吗?