Int64.Equals Method in C# with Examples

CsharpServer Side ProgrammingProgramming

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

Syntax

Following is the syntax −

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

Above, the parameter ob is an Int64 value to compare to this instance, whereas the parameter ob is an object to compare with this instance.

Example

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

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 now see another example to implement the Int64.Equals() method −

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
raja
Published on 13-Nov-2019 05:52:03
Advertisements