Int64.Equals 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回表示這個執行個體是否等於指定物件或 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
參數
傳回
如果 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.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":::
適用於
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
與這個執行個體相互比較的物件。
傳回
如果 true
是 obj
的執行個體,且等於這個執行個體的值,則為 Int64,否則為 false
。
範例
下列程式碼範例說明如何在的 Equals
內容中使用 Int64
、比較兩個 long 值,以及在 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 = "try-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":::