-2

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");
}
G. Lari
  • 435
  • 2
  • 14
  • 4
    have you tried it? – Daniel A. White Mar 19 '21 at 15:02
  • Sure. And I have not been able. But just wondering if there is any escamotage to do it. It's just a curiosity. – G. Lari Mar 19 '21 at 15:07
  • Any solution to make the code compile is going to involve way more code than the 2 characters you need to type out (or one depending on your autocomplete settings) for the statement block. – Servy Mar 19 '21 at 15:39

1 Answers1

2

Maybe I have found a solution:

void Checkup() => _ = condition ? throw new InvalidOperationException("Error") : 0;
G. Lari
  • 435
  • 2
  • 14