Indicate whether this instance is equal to a specified object or UInt16 in C#


To indicate whether this instance is equal to a specified object or UInt16, the code is as follows −

Example

 Live Demo

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 −

 Live Demo

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

Updated on: 11-Dec-2019

41 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements