Blindy Blindy - 1 month ago 8
C# Question

Possible mistaken empty statement – compiler is mistaken in this case

I feel so silly asking this, but how do I instruct the compiler that it is not a mistake? I really intend to have an "empty" branch in my

if
statement, with a clear
else
at the end catching the bad values.

I can of course restructure the whole
if
around this, but it'll be less clear as a result, and working around a silly compiler warning seems weird. Also I'd prefer if I didn't have to disable the entire warning, just for this specific statement.

Answer

Well I knew it was something silly, simply using an empty block gets rid of it:

if(condition1)
  // code here
else if(condition2)
  // code here
else if(condition3)
{
    //nothing to do
}
else
  // error case here