UInt16.Equals Method in C# with Examples

CsharpServer Side ProgrammingProgramming

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

Syntax

Following is the syntax −

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

Above, the parameter ob for the 1st syntax is an object to compare to this instance and the parameter ob for the 2nd syntax is the 16-bit unsigned integer to compare to this instance.

Example

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

using System;
public class Demo {
   public static void Main(){
      ushort val1 = 52;
      ushort val2 = 10;
      bool res = val1.Equals(val2);
      Console.WriteLine("Return value (comparison) = "+res);
      if (res)
         Console.WriteLine("val1 = val2");
      else
         Console.WriteLine("val1 != val2");
   }
}

Output

This will produce the following output −

Return value (comparison) = False
val1 != val2

Example

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

using System;
public class Demo {
   public static void Main(){
      ushort val1 = 100;
      ushort val2 = 100;
      bool res = val1.Equals(val2);
      Console.WriteLine("Return value (comparison) = "+res);
      if (res)
         Console.WriteLine("val1 = val2");
      else
         Console.WriteLine("val1 != val2");
   }
}

Output

This will produce the following output −

Return value (comparison) = True 
val1 = val2
raja
Published on 05-Nov-2019 07:53:24
Advertisements