III- Relational Operator
In c#, Relational Operators are useful to check the relation between two operands like we can determine whether two operand values equal or not, etc., based on our requirements.
Generally, the c# relational operators will return true only when the defined operands relationship becomes true. Otherwise, it will return false.
For example, we have integer variables a = 10, b = 20. If we apply a relational operator >= (a >= b), we will get the result false because the variable “a” contains a value that is less than variable b.
C# Relational Operators Example
using System;
namespace Tutlane
{
class Program
{
static void Main(string[] args)
{
bool result;
int x = 10, y = 20;
result = (x == y);
Console.WriteLine("Equal to Operator: " + result);
result = (x > y);
Console.WriteLine("Greater than Operator: " + result);
result = (x <= y);
Console.WriteLine("Lesser than or Equal to: "+ result);
result = (x != y);
Console.WriteLine("Not Equal to Operator: " + result);
Console.WriteLine("Press Enter Key to Exit..");
Console.ReadLine();
}
}
}
0 Comments