Q:

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

belongs to collection: C# Basic Programs | basics

0

Equal To (==) and Not Equal To (!=) operators are used for comparison, they are used to compare two operands and return Boolean value.

Equal To (==) operator returns True – if both operand's values are equal, else it returns False.

Not Equal To (!=) operator returns True – both operand's values are not equal, else it returns False.

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

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C# code to demonstrate 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 IncludeHelp
{
    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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate example of relational op... >>
<< C# program to demonstrate example of sizeof() oper...