By 22/07/2015 0 Comments

C# Relational Or Comparison Operators

  • Relational operators compare two values or variables with each other.
  • These operators compare one value with another value such as these operators compare which value is equal with other value? Which value is greater than other? Which value is not equal with other value etc.
  • Two values compare by these operators are called a condition.
  • They produce result in boolean which is true or false.
  • All primitive or simple types can be compared by these operators.

Suppose:

int v1 = 10, v2 = 10;

OPERATOR DESCRIPTION
== Equal to, this operator compares the equality of v1 variable with v2 e.g. (v1 == v2) = true, if these both variables are equal than it returns true otherwise false.
!= Not equal to, this operator compares the inequality of v1 variable with v2 e.g. (v1 != v2) = false, if these both variables are not equal than it returns true otherwise false.
> Greater than, this operator compares the greatness of v1 variable with v2 e.g. (v1 > v2) = false , if v1 variable is greater than v2 it returns true otherwise false.
< Less than, this operator compares the less of v1 variable with v2 e.g. (v1 < v2) = false, if v1 variable is lesser than v2 it returns true otherwise false.
>= Greater than or equal to, this operator compares the greatness or equality of v1 variable with v2 e.g. (v1 >= v2) = true, if v1 variable is greater than or equal to v2 it returns true otherwise false.
<= Less than or equal to, this operator compares the less or equality of v1 variable with v2 e.g. (v1 <= v2) = true, if v1 variable is less than or equal to v2 it returns true otherwise false.


Example:

using System;
namespace csharpBasic
{
  // Start class definition / declaration.
    class Program
    {
      // Static main method void type declaration.
        static void Main(string[] args)
        {
            /* Initialize and declare v1
			   and v2 variables with values
			   of 10,10 */
            int v1 = 10, v2 = 10;

            // Declare a result variable of boolean type.
            bool result;

            // An expression which compares v1 and v2 values using an equal to operator.
            result = (v1 == v2);

            // Print result variable.
            Console.WriteLine(" == {0} ", result);

            // An expression which compares v1 and v2 values using not equal to operator.          
            result = (v1 != v2);      

            Console.WriteLine(" != {0} ", result);

            // An expression which compares v1 and v2 values using greater than operator.
            result = (v1 > v2);

            Console.WriteLine(" > {0} ", result);

            // An expression which compares v1 and v2 values using greater than or equal to operator.
            result = (v1 >= v2);

            Console.WriteLine(" >= {0} ", result);

            // An expression which compares v1 and v2 values using less than operator.
            result = (v1 < v2);

            Console.WriteLine(" < {0} ", result);

            // An expression which compares v1 and v2 values using less than or equal to operator.               
            result = (v1 <= v2);

            Console.WriteLine(" <= {0} ", result);
            Console.ReadKey();

        } // End of main method definition.

    } // End of class.
}






Next Tutorial →



Posted in: C# Basics, C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .