Comparing a variable to multiple values [duplicate]

You could do with with .Contains like this:

if (new[] { BillType.Receipt, BillType.Bill, BillType.Payment}.Contains(type)) {}

Or, create your own extension method that does it with a more readable syntax

public static class MyExtensions
{
    public static bool IsIn<T>(this T @this, params T[] possibles)
    {
        return possibles.Contains(@this);
    }
}

Then call it by:

if (type.IsIn(BillType.Receipt, BillType.Bill, BillType.Payment)) {}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)