在我的代码中,经常需要将一个变量与多个值进行比较:
if ( type == BillType.Bill || type == BillType.Payment || type == BillType.Receipt )
{
// Do stuff
}
我一直在想我能做:
if ( type in ( BillType.Bill, BillType.Payment, BillType.Receipt ) )
{
// Do stuff
}
当然,这是SQL的功劳。
在C#中有更简洁的方法吗?