Relational operators, also known as comparison operators, are used to compare two values and determine the relationship between them. These operators return a boolean value (true or false) based on the comparison result.
using System;
class Program
{
static void Main(string[] args)
{
int a = 10;
int b = 5;
// Equal to (==): Checks if two values are equal.
bool isEqual = (a == b);
Console.WriteLine($"Is {a} equal to {b}? {isEqual}");
// Not equal to (!=): Checks if two values are not equal.
bool isNotEqual = (a != b);
Console.WriteLine($"Is {a} not equal to {b}? {isNotEqual}");
// Greater than (>): Checks if the first value is greater than
the second.
bool isGreaterThan = (a > b);
Console.WriteLine($"Is {a} greater than {b}? {isGreaterThan}");
// Less than (<): Checks if the first value is less than the
second.
bool isLessThan = (a < b);
Console.WriteLine($"Is {a} less than {b}? {isLessThan}");
// Greater than or equal to (>=): Checks if the first value is
greater than or equal to the second.
bool isGreaterThanOrEqual = (a
>= b);
Console.WriteLine($"Is {a} greater than or equal to {b}? {isGreaterThanOrEqual}");
// Less than or equal to (<=): Checks if the first value is
less than or equal to the second.
bool isLessThanOrEqual = (a <=
b);
Console.WriteLine($"Is {a} less than or equal to {b}? {isLessThanOrEqual}");
}
}
//Result
//Is 10 equal to 5? False
//Is 10 not equal to 5? True
//Is 10 greater than 5? True
//Is 10 less than 5? False
//Is 10 greater than or equal to 5? True
//Is 10 less
than or equal to 5? False