当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Int64.Equals用法及代码示例


Int64.Equals()方法用于获取一个值,该值显示当前实例是否等于指定的对象或Int64。此方法的重载列表中有2种方法,如下所示:

    • Equals(Int64)
    • Equals(Object)

Int64.Equals(Int64)

此方法用于返回一个值,该值指示当前实例是否等于指定的Int64值。


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

返回值:如果obj与该实例具有相同的值,则此方法返回true,否则返回false。

以下示例程序旨在说明Int64.Equals(Int64)方法的使用:

范例1:

// 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); 
    } 
}
输出:
45643242 is not equal to 2564233

范例2:

// 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); 
    } 
}
输出:
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

此方法用于返回一个值,该值指示当前实例是否等于指定的对象。

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

返回值:如果obj是Int64的实例,并且此实例的值等于False,则此方法返回true。


以下示例程序旨在说明上述方法的用法:

范例1:

// 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); 
    } 
}
输出:
1879650 is not equal to 0

范例2:

// 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); 
    } 
}
输出:
54547 is not equal to 54585
555 is not equal to 489
10450 is not equal to 10450
745 is equal to 745

参考:



相关用法


注:本文由纯净天空筛选整理自Kirti_Mangal大神的英文原创作品 Int64.Equals Method in C# with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。