Int64.Equals メソッド
定義
オーバーロード
Equals(Int64) |
このインスタンスが指定した Int64 値に等しいかどうかを示す値を返します。Returns a value indicating whether this instance is equal to a specified Int64 value. |
Equals(Object) |
このインスタンスが指定されたオブジェクトに等しいかどうかを示す値を返します。Returns a value indicating whether this instance is equal to a specified object. |
Equals(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
の値がこのインスタンスと同じ場合は true
。それ以外の場合は false
。true
if obj
has the same value as this instance; otherwise, false
.
実装
注釈
このメソッドは、 System.IEquatable<T> インターフェイスを実装し、パラメーターを Equals オブジェクトに変換する必要がないため、より少しのパフォーマンスを発揮し obj
ます。This method implements the System.IEquatable<T> interface, and performs slightly better than Equals because it does not have to convert the obj
parameter to an object.
注意 (呼び出し元)
コンパイラのオーバーロードの解決では、2つのメソッドオーバーロードの動作の明らかな違いを考慮することができ Equals(Int64) ます。Compiler overload resolution may account for an apparent difference in the behavior of the two Equals(Int64) method overloads. 引数との間の暗黙の変換が定義されていて、 obj
Int64 引数がとして型指定されていない場合 Object 、コンパイラは暗黙的な変換を実行し、メソッドを呼び出し Equals(Int64) ます。If an implicit conversion between the obj
argument and an Int64 is defined and the argument is not typed as an Object, compilers perform an implicit conversion and call the Equals(Int64) method. それ以外の場合は、メソッドを呼び出します。このメソッドは、 Equals(Object) false
obj
引数が値でない場合は常にを返し Int64 ます。Otherwise, they call the Equals(Object) method, which always returns false
if its obj
argument is not an Int64 value. 次の例は、2つのメソッドオーバーロード間の動作の違いを示しています。The following example illustrates the difference in behavior between the two method overloads. Byte、、 SByte 、、、およびの各値の場合、最初の比較では、 Int16 コンパイラが UInt16 Int32 UInt32 true
自動的に拡大変換を実行して Equals(Int64) メソッドを呼び出します。一方、2番目の比較では、 false
コンパイラがメソッドを呼び出すため Equals(Object) 、が返されます。In the case of the Byte, SByte, Int16, UInt16, Int32, and UInt32 values, the first comparison returns true
because the compiler automatically performs a widening conversion and calls the Equals(Int64) method, whereas the second comparison returns false
because the compiler calls the Equals(Object) method.
[! code-csharp# 1][! code-vb system.string# 1][!code-csharpSystem.Int64.Equals#1] [!code-vbSystem.Int64.Equals#1]
適用対象
Equals(Object)
このインスタンスが指定されたオブジェクトに等しいかどうかを示す値を返します。Returns a value indicating whether this instance is equal to a specified 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
このインスタンスと比較するオブジェクト。An object to compare with this instance.
戻り値
true
が obj
のインスタンスで、このインスタンスの値に等しい場合は Int64。それ以外の場合は false
。true
if obj
is an instance of an Int64 and equals the value of this instance; otherwise, false
.
例
次のコード例では、 Equals
のコンテキストでを使用し Int64
、2つの long 型の値を比較して、 true
同じ数値を表す場合はを返し false
ます。それ以外の場合はを返します。The following code example illustrates the use of Equals
in the context of Int64
, comparing two long values and returning true
if they represent the same number, or false
if they do not.
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");
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
注意 (呼び出し元)
コンパイラのオーバーロードの解決では、2つのメソッドオーバーロードの動作の明らかな違いを考慮することができ Equals(Int64) ます。Compiler overload resolution may account for an apparent difference in the behavior of the two Equals(Int64) method overloads. 引数との間の暗黙の変換が定義されていて、 obj
Int64 引数がとして型指定されていない場合 Object 、コンパイラは暗黙的な変換を実行し、メソッドを呼び出し Equals(Int64) ます。If an implicit conversion between the obj
argument and an Int64 is defined and the argument is not typed as an Object, compilers perform an implicit conversion and call the Equals(Int64) method. それ以外の場合は、メソッドを呼び出します。このメソッドは、 Equals(Object) false
obj
引数が値でない場合は常にを返し Int64 ます。Otherwise, they call the Equals(Object) method, which always returns false
if its obj
argument is not an Int64 value. 次の例は、2つのメソッドオーバーロード間の動作の違いを示しています。The following example illustrates the difference in behavior between the two method overloads. Byte、、 SByte 、、、およびの各値の場合、最初の比較では、 Int16 コンパイラが UInt16 Int32 UInt32 true
自動的に拡大変換を実行して Equals(Int64) メソッドを呼び出します。一方、2番目の比較では、 false
コンパイラがメソッドを呼び出すため Equals(Object) 、が返されます。In the case of the Byte, SByte, Int16, UInt16, Int32, and UInt32 values, the first comparison returns true
because the compiler automatically performs a widening conversion and calls the Equals(Int64) method, whereas the second comparison returns false
because the compiler calls the Equals(Object) method.
[! code-csharp# 1][! code-vb system.string# 1][!code-csharpSystem.Int64.Equals#1] [!code-vbSystem.Int64.Equals#1]