Int16.Equals Metoda
Definicja
Przeciążenia
Equals(Int16) |
Zwraca wartość wskazującą, czy to wystąpienie jest równe określonej Int16 wartości.Returns a value indicating whether this instance is equal to a specified Int16 value. |
Equals(Object) |
Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.Returns a value indicating whether this instance is equal to a specified object. |
Equals(Int16)
public:
virtual bool Equals(short obj);
public bool Equals (short obj);
override this.Equals : int16 -> bool
Public Function Equals (obj As Short) As Boolean
Parametry
Zwraca
true
Jeśli obj
ma taką samą wartość jak to wystąpienie; w przeciwnym razie, false
.true
if obj
has the same value as this instance; otherwise, false
.
Implementuje
Uwagi
Ta metoda implementuje System.IEquatable<T> interfejs i wykonuje nieco lepsze niż, Equals ponieważ nie musi skonwertować obj
parametru do obiektu.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.
Uwagi dotyczące wywoływania
Rozwiązanie do przeciążenia kompilatora może uwzględniać pozorną różnicę w zachowaniu dwóch Equals(Int16) przeciążeń metod.Compiler overload resolution may account for an apparent difference in the behavior of the two Equals(Int16) method overloads. Jeśli niejawna konwersja między obj
argumentem a Int16 jest zdefiniowana, a argument nie jest typu jako Object , kompilatory wykonują niejawną konwersję i wywołują Equals(Int16) metodę.If an implicit conversion between the obj
argument and an Int16 is defined and the argument is not typed as an Object, compilers perform an implicit conversion and call the Equals(Int16) method. W przeciwnym razie wywołuje Equals(Object) metodę, która zawsze zwraca, false
Jeśli jej obj
argument nie jest Int16 wartością.Otherwise, they call the Equals(Object) method, which always returns false
if its obj
argument is not an Int16 value. Poniższy przykład ilustruje różnice w zachowaniu między dwoma przeciążeniami metod.The following example illustrates the difference in behavior between the two method overloads. W przypadku Byte i SByte wartości, pierwsze porównanie zwraca, true
ponieważ kompilator automatycznie wykonuje konwersję rozszerzającą i wywołuje Equals(Int16) metodę, podczas gdy false
kompilator wywołuje Equals(Object) metodę.In the case of the Byte and SByte values, the first comparison returns true
because the compiler automatically performs a widening conversion and calls the Equals(Int16) method, whereas the second comparison returns false
because the compiler calls the Equals(Object) method.
[! code-CSharpSystem. Int16. Equals # 1] [! code — VBSystem. Int16. Equals # 1][!code-csharpSystem.Int16.Equals#1] [!code-vbSystem.Int16.Equals#1]
Zobacz też
Dotyczy
Equals(Object)
Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.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
Parametry
- obj
- Object
Obiekt, który ma zostać porównany z tym wystąpieniem.An object to compare to this instance.
Zwraca
true
Jeśli obj
jest wystąpieniem Int16 i jest równa wartości tego wystąpienia; w przeciwnym razie, false
.true
if obj
is an instance of Int16 and equals the value of this instance; otherwise, false
.
Przykłady
Poniższy przykład kodu ilustruje użycie Equals
w kontekście Int16
, porównując dwa krótkie wartości i zwracając, true
czy reprezentują ten sam numer, czy też false
nie.The following code example illustrates the use of Equals
in the context of Int16
, comparing two short values and returning true
if they represent the same number, or false
if they do not.
Int16 myVariable1 = 20;
Int16 myVariable2 = 20;
// 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" );
Int16 myVariable1 = 20;
Int16 myVariable2 = 20;
// 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 Int16 = 20
Dim myVariable2 As Int16 = 20
' 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
Uwagi dotyczące wywoływania
Rozwiązanie do przeciążenia kompilatora może uwzględniać pozorną różnicę w zachowaniu dwóch Equals(Int16) przeciążeń metod.Compiler overload resolution may account for an apparent difference in the behavior of the two Equals(Int16) method overloads. Jeśli niejawna konwersja między obj
argumentem a Int16 jest zdefiniowana, a argument nie jest typu jako Object , kompilatory wykonują niejawną konwersję i wywołują Equals(Int16) metodę.If an implicit conversion between the obj
argument and an Int16 is defined and the argument is not typed as an Object, compilers perform an implicit conversion and call the Equals(Int16) method. W przeciwnym razie wywołuje Equals(Object) metodę, która zawsze zwraca, false
Jeśli jej obj
argument nie jest Int16 wartością.Otherwise, they call the Equals(Object) method, which always returns false
if its obj
argument is not an Int16 value. Poniższy przykład ilustruje różnice w zachowaniu między dwoma przeciążeniami metod.The following example illustrates the difference in behavior between the two method overloads. W przypadku Byte i SByte wartości, pierwsze porównanie zwraca, true
ponieważ kompilator automatycznie wykonuje konwersję rozszerzającą i wywołuje Equals(Int16) metodę, podczas gdy false
kompilator wywołuje Equals(Object) metodę.In the case of the Byte and SByte values, the first comparison returns true
because the compiler automatically performs a widening conversion and calls the Equals(Int16) method, whereas the second comparison returns false
because the compiler calls the Equals(Object) method.
[! code-CSharpSystem. Int16. Equals # 1] [! code — VBSystem. Int16. Equals # 1][!code-csharpSystem.Int16.Equals#1] [!code-vbSystem.Int16.Equals#1]