UInt32.Equals Метод
Определение
Перегрузки
Equals(Object) |
Возвращает значение, показывающее, равен ли данный экземпляр заданному объекту.Returns a value indicating whether this instance is equal to a specified object. |
Equals(UInt32) |
Возвращает значение, позволяющее определить, равен ли данный экземпляр заданному объекту типа UInt32.Returns a value indicating whether this instance is equal to a specified UInt32. |
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);
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
является экземпляром типа UInt32 и равен значению данного экземпляра; в противном случае — значение false
.true
if obj
is an instance of UInt32 and equals the value of this instance; otherwise, false
.
Примеры
В следующем примере кода демонстрируется Equals метод.The following code example demonstrates the Equals method.
UInt32 myVariable1 = 20;
UInt32 myVariable2 = 20;
// 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" );
UInt32 myVariable1 = 20;
UInt32 myVariable2 = 20;
// 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 UInt32 = UInt32.Parse(20)
Dim myVariable2 As UInt32 = UInt32.Parse(20)
' 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(UInt32) перегрузок метода.Compiler overload resolution may account for an apparent difference in the behavior of the two Equals(UInt32) method overloads. Если неявное преобразование между obj
аргументом и UInt32 определено и аргумент не типизирован как Object , компилятор выполняет неявное преобразование и вызывает Equals(UInt32) метод.If an implicit conversion between the obj
argument and a UInt32 is defined and the argument is not typed as an Object, compilers perform an implicit conversion and call the Equals(UInt32) method. В противном случае они вызывают Equals(Object) метод, который всегда возвращает, false
если его obj
аргумент не является UInt32 значением.Otherwise, they call the Equals(Object) method, which always returns false
if its obj
argument is not a UInt32 value. В следующем примере показано различие в поведении между двумя перегрузками метода.The following example illustrates the difference in behavior between the two method overloads. В случае Byte UInt16 значений и первое сравнение возвращает, true
поскольку компилятор автоматически выполняет расширяющее преобразование и вызывает Equals(UInt32) метод, тогда как второе сравнение возвращает, false
так как компилятор вызывает Equals(Object) метод.In the case of Byte and UInt16 values, the first comparison returns true
because the compiler automatically performs a widening conversion and calls the Equals(UInt32) method, whereas the second comparison returns false
because the compiler calls the Equals(Object) method.
[! код-CSharpSystem. UInt32. Equals # 1] [! code-VBSystem. UInt32. Equals # 1][!code-csharpSystem.UInt32.Equals#1] [!code-vbSystem.UInt32.Equals#1]
См. также раздел
Применяется к
Equals(UInt32)
public:
virtual bool Equals(System::UInt32 obj);
public bool Equals (uint obj);
override this.Equals : uint32 -> bool
Public Function Equals (obj As UInteger) As Boolean
Параметры
- obj
- UInt32
Значение для сравнения с данным экземпляром.A value to compare to this instance.
Возвращаемое значение
true
, если значение параметра obj
совпадает со значением данного экземпляра; в противном случае — false
.true
if obj
has the same value as this instance; otherwise, false
.
Реализации
Комментарии
Этот метод реализует System.IEquatable<T> интерфейс и работает немного лучше, чем метод, Equals(Object) поскольку ему не нужно преобразовывать obj
параметр в объект.This method implements the System.IEquatable<T> interface, and performs slightly better than the Equals(Object) method because it does not have to convert the obj
parameter to an object.
Примечания для тех, кто вызывает этот метод
Разрешение перегрузки компилятора может учитывать очевидную разницу в поведении двух Equals(UInt32) перегрузок метода.Compiler overload resolution may account for an apparent difference in the behavior of the two Equals(UInt32) method overloads. Если неявное преобразование между obj
аргументом и UInt32 определено и аргумент не типизирован как Object , компилятор выполняет неявное преобразование и вызывает Equals(UInt32) метод.If an implicit conversion between the obj
argument and a UInt32 is defined and the argument is not typed as an Object, compilers perform an implicit conversion and call the Equals(UInt32) method. В противном случае они вызывают Equals(Object) метод, который всегда возвращает, false
если его obj
аргумент не является UInt32 значением.Otherwise, they call the Equals(Object) method, which always returns false
if its obj
argument is not a UInt32 value. В следующем примере показано различие в поведении между двумя перегрузками метода.The following example illustrates the difference in behavior between the two method overloads. В случае Byte UInt16 значений и первое сравнение возвращает, true
поскольку компилятор автоматически выполняет расширяющее преобразование и вызывает Equals(UInt32) метод, тогда как второе сравнение возвращает, false
так как компилятор вызывает Equals(Object) метод.In the case of Byte and UInt16 values, the first comparison returns true
because the compiler automatically performs a widening conversion and calls the Equals(UInt32) method, whereas the second comparison returns false
because the compiler calls the Equals(Object) method.
[! код-CSharpSystem. UInt32. Equals # 1] [! code-VBSystem. UInt32. Equals # 1][!code-csharpSystem.UInt32.Equals#1] [!code-vbSystem.UInt32.Equals#1]