Int64.Equals 方法

定义

返回一个值,该值指示此实例是否与指定的对象或 Int64 相等。

重载

Equals(Int64)

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

Equals(Object)

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

Equals(Int64)

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

public:
 virtual bool Equals(long obj);
public bool Equals (long obj);
override this.Equals : int64 -> bool
Public Function Equals (obj As Long) As Boolean

参数

obj
Int64

要与此实例进行比较的 Int64 值。

返回

Boolean

如果 true 的值与此实例相同,则为 obj;否则为 false

实现

注解

此方法实现 接口,并且性能略好于 ,因为它无需将 System.IEquatable<T> Equals obj 参数转换为 对象。

调用方说明

编译器重载解析可能会导致两个方法重载的行为 Equals(Int64) 明显不同。 如果定义了 参数和 之间的隐式转换,并且参数未类型化为 ,则编译器将执行隐式 obj Int64 Object 转换并调用 Equals(Int64) 方法。 否则,它们调用 方法,如果其参数不是值, Equals(Object) false obj 则该方法始终 Int64 返回 。 下面的示例说明了两个方法重载之间的行为差异。 对于 、、 和 值,第一个比较返回 ,因为编译器自动执行扩大转换并调用 方法,而第二个比较返回 ,因为 Byte SByte Int16 UInt16 Int32 UInt32 true Equals(Int64) false 编译器调用 Equals(Object) 方法。

:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.equals/cs/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.equals/vb/equalsoverl.vb" id="Snippet1":::

适用于

Equals(Object)

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

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object obj);
public override bool Equals (object? obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

参数

obj
Object

与此实例进行比较的对象。

返回

Boolean

如果 trueobj 的实例并且等于此实例的值,则为 Int64;否则为 false

示例

下面的代码示例演示如何在 的上下文中使用 ,比较两个长值,如果它们表示相同的数字,则返回 ;如果它们不表示,则 Equals Int64 返回 true false

Int64 myVariable1 = 80;
Int64 myVariable2 = 80;

// Get and display the declaring type.
Console::WriteLine( "\nType of 'myVariable1' is ' {0}' and  value is : {1}", myVariable1.GetType(), myVariable1 );
Console::WriteLine( "Type of 'myVariable2' is ' {0}' and  value is : {1}", myVariable2.GetType(), myVariable2 );

// Compare 'myVariable1' instance with 'myVariable2' Object.
if ( myVariable1.Equals( myVariable2 ) )
      Console::WriteLine( "\nStructures 'myVariable1' and 'myVariable2' are equal" );
else
      Console::WriteLine( "\nStructures 'myVariable1' and 'myVariable2' are not equal" );
Int64 myVariable1 = 80;
Int64 myVariable2 = 80;

// Get and display the declaring type.
Console.WriteLine("\nType of 'myVariable1' is '{0}' and"+
     " value is :{1}",myVariable1.GetType(), myVariable1);
Console.WriteLine("Type of 'myVariable2' is '{0}' and"+
     " value is :{1}",myVariable2.GetType(), myVariable2);

// Compare 'myVariable1' instance with 'myVariable2' Object.
if( myVariable1.Equals( myVariable2 ) )
   Console.WriteLine( "\nStructures 'myVariable1' and "+
         "'myVariable2' are equal");
else
   Console.WriteLine( "\nStructures 'myVariable1' and "+
         "'myVariable2' are not equal");
let myVariable1 = 80L
let myVariable2 = 80L

// Get and display the declaring type.
printfn $"\nType of 'myVariable1' is '{myVariable1.GetType()}' and value is: {myVariable1}"
printfn $"\nType of 'myVariable2' is '{myVariable2.GetType()}' and value is: {myVariable2}"

// Compare 'myVariable1' instance with 'myVariable2' Object.
if myVariable1.Equals myVariable2 then
    printfn "\nStructures 'myVariable1' and 'myVariable2' are equal"
else
    printfn "\nStructures 'myVariable1' and 'myVariable2' are not equal"
Dim myVariable1 As Int64 = 80
Dim myVariable2 As Int64 = 80

' Get and display the declaring type.
Console.WriteLine(ControlChars.NewLine + "Type of 'myVariable1' is '{0}' and" +  _
            " value is :{1}", myVariable1.GetType().ToString(), myVariable1.ToString())
Console.WriteLine("Type of 'myVariable2' is '{0}' and" +  _
         " value is :{1}", myVariable2.GetType().ToString(), myVariable2.ToString())

' Compare 'myVariable1' instance with 'myVariable2' Object.
If myVariable1.Equals(myVariable2) Then
   Console.WriteLine(ControlChars.NewLine + "Structures 'myVariable1' and " + _
            "'myVariable2' are equal")
Else
   Console.WriteLine(ControlChars.NewLine + "Structures 'myVariable1' and " +  _
         "'myVariable2' are not equal")
End If

调用方说明

编译器重载解析可能会导致两个方法重载的行为 Equals(Int64) 明显不同。 如果定义了 参数和 之间的隐式转换,并且参数未类型化为 ,则编译器将执行隐式 obj Int64 Object 转换并调用 Equals(Int64) 方法。 否则,它们调用 方法,如果其参数不是值, Equals(Object) false obj 则该方法始终 Int64 返回 。 下面的示例说明了两个方法重载之间的行为差异。 对于 、、 和 值,第一个比较返回 ,因为编译器自动执行扩大转换并调用 方法,而第二个比较返回 ,因为 Byte SByte Int16 UInt16 Int32 UInt32 true Equals(Int64) false 编译器调用 Equals(Object) 方法。

::: code language = "csharp" source = "~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int64.equals/cs/equalsoverl.cs" interactive = "dotnet" id = "Snippet1":::::: code language = "fsharp.core" source = "~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs" id = "Snippet1":::::: code language = "vb" source = "~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.equals/vb/equalsoverl.vb" id = "Snippet1":::

另请参阅

适用于