Condition in C# is a statement that evaluates to true or false. It is used to control the flow of execution in a C# program.
Example 1: If statement
int num = 10;
if (num > 0) { Console.WriteLine("The number is positive."); } else if (num < 0) { Console.WriteLine("The number is negative."); } else { Console.WriteLine("The number is zero."); }
This code uses the if statement to determine if the value of num is positive, negative or zero.
Example 2: Switch statement
int month = 6;
switch (month) { case 1: Console.WriteLine("January"); break; case 2: Console.WriteLine("February"); break; case 3: Console.WriteLine("March"); break; case 4: Console.WriteLine("April"); break; case 5: Console.WriteLine("May"); break; case 6: Console.WriteLine("June"); break; default: Console.WriteLine("Invalid month"); break; }
This code uses the switch statement to determine the name of the month based on its value.
The Condition statements and examples mentioned above are inbuilt features of the C# language and do not require any external packages or libraries.
C# (CSharp) Condition - 60 examples found. These are the top rated real world C# (CSharp) examples of Condition extracted from open source projects. You can rate examples to help us improve the quality of examples.