Relational Operators : Logical Relational Operators « Operator « C# / CSharp Tutorial






The relational operators are as follows:

OperatorMeaning
==Equal to
!=Not equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to


using System;

class MainClass
{
  static void Main(string[] args)
  {
    int a = 10, b = 20, c = 30;

    if (a < 15 && b < 20)
      c = 10;
        Console.WriteLine(c);

    if (a < 15 || b < 20)
      c = 15;
        
        Console.WriteLine(c);

    if (!(a == 15))
      c = 25;
      
        Console.WriteLine(c);
  }
}
using System;

class MainClass
{
  static void Main(string[] args)
  {
    int a, b;

    a = 1;
    b = 2;
    if (a > b)
      b = 10;

        Console.WriteLine(b);

    if (b < a)
      a = 10;
        
        Console.WriteLine(a);

    if (a >= b)
      b = 20;

        Console.WriteLine(b);

    if (b <= a)
      a = 20;

        Console.WriteLine(a);

    if (a == b)
      b = 5;

        Console.WriteLine(b);

    if (b != a)
      b = a;
      
        Console.WriteLine(b);      
  }
}
2
1
2
1
2
1
using System; 
 
class Example {    
  public static void Main() {    
    int i, j; 
 
    i = 10; 
    j = 11; 
    if(i < j) 
       Console.WriteLine("i < j"); 
    if(i <= j) 
       Console.WriteLine("i <= j"); 
    if(i != j) 
       Console.WriteLine("i != j"); 
    if(i == j) 
       Console.WriteLine("this won't execute"); 
    if(i >= j) 
       Console.WriteLine("this won't execute"); 
    if(i > j) 
       Console.WriteLine("this won't execute"); 
 
  }    
}
i < j
i <= j
i != j








3.6.Logical Relational Operators
3.6.1.Relational Operators
3.6.2.Logical operators
3.6.3.false expressions for operators: ==, > and <
3.6.4.true expressions for operators: !=, >, <
3.6.5.Boolean logical AND operator
3.6.6.Boolean logical OR operator
3.6.7.Boolean logical NOT operator
3.6.8.Logical operators with an if statement
3.6.9.List of Boolean Operators