Best way to check multiple boolean conditions in C# if statements

boolean, c#, if-statement

Solution

It is better to capture the intent of the operation instead of explicitly check the boolean values.

For example:

public void Check()
{
   if (HasOrdered())
   {
      // do logic
   }
}

private bool HasOrdered()
{
    return a && !b && !c;
}

private bool HasBooked()
{
    return a && b && !c;
}

Problem

I have 3 booleans on my code (C#) and an `int32` property that depends on what booleans are `true` and `false`. Whats the best way to accomplish this in another way than if statements like: ``` if(a && b && !c) d = 1; if(a && !b && !c) d = 2; //etc.. ect... ``` EDIT: The 3 booleans must have every combination possible to set the int32 value. EDIT 2: The value of "d" can be the same for two different boolean comparations.

Original source