Is it possible to write an expression-bodied member containing an if statement?

395 Views Asked by At

I wonder if it is possible to rewrite the following method using an expression-bodied member:

private void Checkup()
{
   if (errorCondition) throw new InvalidOperationException("Error");
}
1

There are 1 best solutions below

0
G. Lari On BEST ANSWER

Maybe I have found a solution:

void Checkup() => _ = condition ? throw new InvalidOperationException("Error") : 0;