Int16.Equals Method in C# with Examples


The Int16.Equals() method in C# is used to return a value indicating whether this instance is equal to a specified object or Int16.

Syntax

Following is the syntax −

public bool Equals (short ob);
public override bool Equals (object ob);

Above, the parameter ob for the 1st syntax is an Int16 value to compare to this instance.

The parameter ob for the 2nd syntax is the object to compare to this instance.

Example

Let us now see an example to implement the Int16.Equals() method −

using System;
public class Demo {
   public static void Main(){
      short val1 = 15;
      short val2 = 17;
      Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));
   }
}

Output

This will produce the following output −

Are they equal? = False

Example

Let us now see another example to implement the Int16.Equals() method −

using System;
public class Demo {
   public static void Main(){
      short val1 = 25;
      short val2 = 25;
      Console.WriteLine("Value1 = "+val1);
      Console.WriteLine("Value2 = "+val2);
      Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));
   }
}

Output

This will produce the following output −

Value1 = 25
Value2 = 25
Are they equal? = True

Updated on: 08-Nov-2019

80 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements