Int64.Equals Method in C# with Examples

Int64.Equals() Method is used to get a value that shows whether the current instance is equal to a specified object or Int64. There are 2 methods in the overload list of this method as follows:

  • Equals(Int64) Method
  • Equals(Object) Method

Int64.Equals(Int64)

This method is used to return a value indicating whether the current instance is equal to a specified Int64 value or not.



Syntax: public bool Equals (long obj);
Here, it takes a Int64 value to compare to this instance.

Return Value: This method returns true if obj has the same value as this instance otherwise, false.

Below programs illustrate the use of Int64.Equals(Int64) Method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Int64.Equals(Int64) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing value1
        long value1 = 45643242;
  
        // Declaring and initializing value2
        long value2 = 2564233;
  
        // using Equals(Int64) method
        bool status = value1.Equals(value2);
  
        // checking the status
        if (status)
            Console.WriteLine("{0} is equal to {1}",
                                    value1, value2);
        else
            Console.WriteLine("{0} is not equal to {1}",
                                        value1, value2);
    }
}

chevron_right


Output:

45643242 is not equal to 2564233

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Int64.Equals(Int64) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // calling get() method
        get(44355, 578);
        get(423445, 423445);
        get(12560, 28960);
        get(778, 798);
    }
  
    // defining get() method
    public static void get(long value1,
                           long value2)
    {
  
        // using Equals(Int64) method
        bool status = value1.Equals(value2);
  
        // checking the status
        if (status)
            Console.WriteLine("{0} is equal to {1}",
                                    value1, value2);
        else
            Console.WriteLine("{0} is not equal to {1}",
                                        value1, value2);
    }
}

chevron_right


Output:

44355 is not equal to 578
423445 is equal to 423445
12560 is not equal to 28960
778 is not equal to 798

Int64.Equals(Object) Method

This method is used to returns a value indicating whether the current instance is equal to a specified object or not.

Syntax: public override bool Equals (object obj);
Here, it takes an object to compare with this instance.

Return Value: This method returns true if obj is an instance of Int64 and equals the value of this instance otherwise, false.


Below programs illustrate the use of the above-discussed method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Int64.Equals(Object) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing value1
        long value1 = 1879650;
  
        // Declaring and initializing value2
        object value2 = 1/45;
  
        // using Equals(object) method
        bool status = value1.Equals(value2);
  
        // checking the status
        if (status)
            Console.WriteLine("{0} is equal to {1}",
                                    value1, value2);
        else
            Console.WriteLine("{0} is not equal to {1}",
                                        value1, value2);
    }
}

chevron_right


Output:

1879650 is not equal to 0

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Int64.Equals(Object) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // calling get() method
        get(54547, 54585);
        get(555, 489);
        get(10450, 10450);
        get(745, 745);
    }
  
    // defining get() method
    public static void get(long value1,
                        object value2)
    {
  
        // using Equals(object) method
        bool status = value1.Equals(value2);
  
        // checking the status
        if (status)
            Console.WriteLine("{0} is equal to {1}",
                                    value1, value2);
        else
            Console.WriteLine("{0} is not equal to {1}",
                                        value1, value2);
    }
}

chevron_right


Output:

54547 is not equal to 54585
555 is not equal to 489
10450 is not equal to 10450
745 is equal to 745

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.