C# program to demonstrate example of equal to and not equal to operators

Syntax:

    Operand1 == Operand2
    Operand1 != Operand2

Example:

    Input:
    int a = 10;
    int b = 3;
    
    Console.WriteLine("a==b: {0}", (a == b));
    Console.WriteLine("a!=b: {0}", (a != b));

    Output:
    a==b: False
    a!=b: True

C# code to demonstrate an example of Equal To and Not Equal To operators:

// C# program to demonstrate example of 
// equal to and not equal to operators
using System;
using System.IO;
using System.Text;

namespace JustTechReview
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {

            int a = 10;
            int b = 3;

            //printing return type
            Console.WriteLine("Return type of == operator: {0}", (a == b).GetType());
            Console.WriteLine("Return type of != operator: {0}", (a != b).GetType());

            //printing return values
            Console.WriteLine("a==b: {0}", (a == b));
            Console.WriteLine("a!=b: {0}", (a != b));

            //checking conditions
            if (a == b)
                Console.WriteLine("both are equal");
            else
                Console.WriteLine("both are not equal");

            //checking conditions in another way
            if ((a == b)==true )
                Console.WriteLine("both are equal");
            else
                Console.WriteLine("both are not equal");

            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}

Output:

Return type of == operator: System.Boolean
Return type of != operator: System.Boolean
a==b: False
a!=b: True
both are not equal
both are not equal

Leave a Comment

error: Alert: Content is protected!!