UInt64.Equals 方法
定义
重载
| Equals(Object) |
返回一个值,该值指示此实例是否等于指定的对象。Returns a value indicating whether this instance is equal to a specified object. |
| Equals(UInt64) |
返回一个值,该值指示此实例是否等于指定的 UInt64 值。Returns a value indicating whether this instance is equal to a specified UInt64 value. |
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 to this instance.
返回
如果 true 是 obj 的实例并且等于此实例的值,则为 UInt64;否则为 false。true if obj is an instance of UInt64 and equals the value of this instance; otherwise, false.
示例
下面的示例演示 Equals 方法。The following example demonstrates the Equals method.
using System;
public class Example
{
public static void Main()
{
object[] values = { (short) 10, (short) 20, 10, 20,
10L, 20L, 10D, 20D, (ushort) 10,
(ushort) 20, 10U, 20U,
10ul, 20ul };
UInt64 baseValue = 20;
String baseType = baseValue.GetType().Name;
foreach (var value in values)
Console.WriteLine("{0} ({1}) = {2} ({3}): {4}",
baseValue, baseType,
value, value.GetType().Name,
baseValue.Equals(value));
}
}
// The example displays the following output:
// 20 (UInt64) = 10 (Int16): False
// 20 (UInt64) = 20 (Int16): False
// 20 (UInt64) = 10 (Int32): False
// 20 (UInt64) = 20 (Int32): False
// 20 (UInt64) = 10 (Int64): False
// 20 (UInt64) = 20 (Int64): False
// 20 (UInt64) = 10 (Double): False
// 20 (UInt64) = 20 (Double): False
// 20 (UInt64) = 10 (UInt16): False
// 20 (UInt64) = 20 (UInt16): False
// 20 (UInt64) = 10 (UInt32): False
// 20 (UInt64) = 20 (UInt32): False
// 20 (UInt64) = 10 (UInt64): False
// 20 (UInt64) = 20 (UInt64): True
Module Example
Public Sub Main()
Dim values() As Object = { 10S, 20S, 10I, 20I, 10L, 20L,
10R, 20R, 10US, 20US, 10UI, 20UI,
10UL, 20UL }
Dim baseValue As UInt64 = 20
Dim baseType As String = baseValue.GetType().Name
For Each value In values
Console.WriteLine("{0} ({1}) = {2} ({3}): {4}",
baseValue, baseType,
value, value.GetType().Name,
baseValue.Equals(value))
Next
End Sub
End Module
' The example displays the following output:
' 20 (UInt64) = 10 (Int16): False
' 20 (UInt64) = 20 (Int16): False
' 20 (UInt64) = 10 (Int32): False
' 20 (UInt64) = 20 (Int32): False
' 20 (UInt64) = 10 (Int64): False
' 20 (UInt64) = 20 (Int64): False
' 20 (UInt64) = 10 (Double): False
' 20 (UInt64) = 20 (Double): False
' 20 (UInt64) = 10 (UInt16): False
' 20 (UInt64) = 20 (UInt16): False
' 20 (UInt64) = 10 (UInt32): False
' 20 (UInt64) = 20 (UInt32): False
' 20 (UInt64) = 10 (UInt64): False
' 20 (UInt64) = 20 (UInt64): True
调用方说明
编译器重载决策可能会考虑两种方法重载行为中的明显差异 Equals(UInt64) 。Compiler overload resolution may account for an apparent difference in the behavior of the two Equals(UInt64) method overloads. 如果定义了参数和 a 之间的隐式转换, obj UInt64 并且参数未键入为,则 Object 编译器会执行隐式转换并调用 Equals(UInt64) 方法。If an implicit conversion between the obj argument and a UInt64 is defined and the argument is not typed as an Object, compilers perform an implicit conversion and call the Equals(UInt64) method. 否则,它们调用 Equals(Object) 方法, false 如果其 obj 参数不是值,则总是返回 UInt64 。Otherwise, they call the Equals(Object) method, which always returns false if its obj argument is not a UInt64 value. 下面的示例演示两个方法重载之间的行为差异。The following example illustrates the difference in behavior between the two method overloads. 对于 Byte 、 UInt16 和 UInt32 值,第一次比较返回,这是 true 因为编译器会自动执行扩大转换并调用 Equals(UInt64) 方法,而第二次比较返回,这是 false 因为编译器调用了 Equals(Object) 方法。In the case of the Byte, UInt16, and UInt32 values, the first comparison returns true because the compiler automatically performs a widening conversion and calls the Equals(UInt64) method, whereas the second comparison returns false because the compiler calls the Equals(Object) method.
[! code-csharpsystem.web. Equals # 2][! code-vbsystem.web. Equals # 2][!code-csharpSystem.UInt64.Equals#2] [!code-vbSystem.UInt64.Equals#2]
另请参阅
适用于
Equals(UInt64)
public:
virtual bool Equals(System::UInt64 obj);
public bool Equals (ulong obj);
override this.Equals : uint64 -> bool
Public Function Equals (obj As ULong) As Boolean
参数
返回
如果 true 的值与此实例相同,则为 obj;否则为 false。true if obj has the same value as this instance; otherwise, false.
实现
示例
下面的示例演示 Equals 方法。The following example demonstrates the Equals method.
using namespace System;
int main()
{
UInt64 value1 = 50;
UInt64 value2 = 50;
// Display the values.
Console::WriteLine("value1: Type: {0} Value: {1}",
value1.GetType()->Name, value1);
Console::WriteLine("value2: Type: {0} Value: {1}",
value2.GetType()->Name, value2);
// Compare the two values.
Console::WriteLine("value1 and value2 are equal: {0}",
value1.Equals(value2));
}
// The example displays the following output:
// value1: Type: UInt64 Value: 50
// value2: Type: UInt64 Value: 50
// value1 and value2 are equal: True
using System;
class Example
{
public static void Main()
{
UInt64 value1 = 50;
UInt64 value2 = 50;
// Display the values.
Console.WriteLine("value1: Type: {0} Value: {1}",
value1.GetType().Name, value1);
Console.WriteLine("value2: Type: {0} Value: {1}",
value2.GetType().Name, value2);
// Compare the two values.
Console.WriteLine("value1 and value2 are equal: {0}",
value1.Equals(value2));
}
}
// The example displays the following output:
// value1: Type: UInt64 Value: 50
// value2: Type: UInt64 Value: 50
// value1 and value2 are equal: True
Class Example
Public Shared Sub Main()
Dim value1 As UInt64 = 50
Dim value2 As UInt64 = 50
'Display the values.
Console.WriteLine("value1: Type: {0} Value: {1}",
value1.GetType().Name, value1)
Console.WriteLine("value2: Type: {0} Value: {1}",
value2.GetType().Name, value2)
' Compare the two values.
Console.WriteLine("value1 and value2 are equal: {0}",
value1.Equals(value2))
End Sub
End Class
' The example displays the following output:
' value1: Type: UInt64 Value: 50
' value2: Type: UInt64 Value: 50
' value1 and value2 are equal: True
注解
此方法实现 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.
调用方说明
编译器重载决策可能会考虑两种方法重载行为中的明显差异 Equals(UInt64) 。Compiler overload resolution may account for an apparent difference in the behavior of the two Equals(UInt64) method overloads. 如果定义了参数和 a 之间的隐式转换, obj UInt64 并且参数未键入为,则 Object 编译器会执行隐式转换并调用 Equals(UInt64) 方法。If an implicit conversion between the obj argument and a UInt64 is defined and the argument is not typed as an Object, compilers perform an implicit conversion and call the Equals(UInt64) method. 否则,它们调用 Equals(Object) 方法, false 如果其 obj 参数不是值,则总是返回 UInt64 。Otherwise, they call the Equals(Object) method, which always returns false if its obj argument is not a UInt64 value. 下面的示例演示两个方法重载之间的行为差异。The following example illustrates the difference in behavior between the two method overloads. 对于 Byte 、 UInt16 和 UInt32 值,第一次比较返回,这是 true 因为编译器会自动执行扩大转换并调用 Equals(UInt64) 方法,而第二次比较返回,这是 false 因为编译器调用了 Equals(Object) 方法。In the case of the Byte, UInt16, and UInt32 values, the first comparison returns true because the compiler automatically performs a widening conversion and calls the Equals(UInt64) method, whereas the second comparison returns false because the compiler calls the Equals(Object) method.
[! code-csharpsystem.web. Equals # 2][! code-vbsystem.web. Equals # 2][!code-csharpSystem.UInt64.Equals#2] [!code-vbSystem.UInt64.Equals#2]