Compare this instance is equal to a specified object or Int64 in C#


To compare this instance is equal to a specified object or Int64, the code is as follows −

Example

 Live Demo

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

Output

This will produce the following output −

Value1 = 150
Value2 = 240
Are they equal? = False

Example

Let us see another example −

 Live Demo

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

Output

This will produce the following output −

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

Updated on: 05-Dec-2019

48 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements