Branching with if and else in C# is straightforward.
To run the program, save it as IfElse.cs and use the C# compiler:
Note that in C#, parentheses are required around conditions, and braces are also required for multi-line code blocks. For single-line code blocks, braces are optional but recommended for clarity.
C# does have a ternary operator (?:), which can be used for simple conditional expressions:
This can be useful for simple conditions, but for more complex logic, a full if statement is often more readable.