Do else if statements exist in C#?

You are correct; there is no such thing as an “else if” statement in C#. It’s just an else where the statement of the alternative clause is itself an if statement.

Of course, the IDE treats “else if” as special so that you get the nice formatting you’d expect.

Note that there is an #elif construct in the “preprocessor” syntax.

Note also that C, C++ and ECMAScript – and I am sure many more C-like languages – also have the property that there is no formal “else if” statement. Rather, in each the behaviour falls out of the definition of “else” as coming before a single statement.

Leave a Comment

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