Javatpoint Logo
Javatpoint Logo

C# if-else

In C# programming, the if statement is used to test the condition. There are various types of if statements in C#.

  • if statement
  • if-else statement
  • nested if statement
  • if-else-if ladder

C# IF Statement

The C# if statement tests the condition. It is executed if condition is true.


if statement in java

C# If Example


It is even number

C# IF-else Statement

The C# if-else statement also tests the condition. It executes the if block if condition is true otherwise else block is executed.


C# if-else statement

C# If-else Example


It is odd number

C# If-else Example: with input from user

In this example, we are getting input from the user using Console.ReadLine() method. It returns string. For numeric value, you need to convert it into int using Convert.ToInt32() method.


Enter a number:11
It is odd number


Enter a number:12
It is even number

C# IF-else-if ladder Statement

The C# if-else-if ladder statement executes one condition from multiple statements.


C# if-else-if statement

C# If else-if Example


Enter a number to check grade:66
C Grade


Enter a number to check grade:-2
wrong number
Next TopicC# switch

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA