Friday, 17 August 2018

C#: Conditional operators

Conditional operators determine whether one operand is greater than, less than, equal to, or not equal to another operand.

Operator
Description
==
equal to
!=
not equal to
> 
greater than
>=
greater than or equal to
< 
less than
<=
less than or equal to


Conditional operators take two operands and return true, if the condition evaluates to true, otherwise return false.

Program.cs
using System;

class Program
{
    static void Main(string[] args)
    {
        int a = 10, b = 11;

        Console.WriteLine("is a equals to a {0}", (a == a));
        Console.WriteLine("is a equals to b {0}", (a == b));
        Console.WriteLine("is a not equals to a {0}", (a != a));
        Console.WriteLine("is a not equals to b {0}", (a != b));
        Console.WriteLine("is a less than a {0}", (a < a));
        Console.WriteLine("is a less than b {0}", (a < b));
        Console.WriteLine("is a less than or equal to a {0}", (a <= a));
        Console.WriteLine("is a less than or equal b {0}", (a <= b));
        Console.WriteLine("is a greater than a {0}", (a > a));
        Console.WriteLine("is a greater than b {0}", (a > b));
        Console.WriteLine("is a greater than or equal to a {0}", (a >= a));
        Console.WriteLine("is a greater than or equal to b {0}", (a >= b));
    }
}

Output
is a equals to a True
is a equals to b False
is a not equals to a False
is a not equals to b True
is a less than a False
is a less than b True
is a less than or equal to a True
is a less than or equal b True
is a greater than a False
is a greater than b False
is a greater than or equal to a True
is a greater than or equal to b False



Previous                                                 Next                                                 Home

No comments:

Post a Comment