Nullable<T>.Equals(Object) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Anger om det aktuella Nullable<T> objektet är lika med ett angivet objekt.
public:
override bool Equals(System::Object ^ other);
public override bool Equals(object other);
public override bool Equals(object? other);
override this.Equals : obj -> bool
Public Overrides Function Equals (other As Object) As Boolean
Parametrar
- other
- Object
Ett objekt.
Returer
trueom parametern other är lika med det aktuella Nullable<T> objektet, annars . false
Den här tabellen beskriver hur likhet definieras för de jämförna värdena:
| Returvärde | Beskrivning |
|---|---|
true | Egenskapen HasValue är false, och parametern other är null (dvs. två null-värden är lika per definition), ELLER HasValue så är trueegenskapen , och värdet som returneras av Value egenskapen är lika med parametern other .
|
false | Egenskapen HasValue för den aktuella Nullable<T> strukturen är true, och parametern other är null, ELLER HasValue egenskapen för den aktuella Nullable<T> strukturen är false, och parametern other är inte null, ELLER HasValue egenskapen för den aktuella Nullable<T> strukturen är true, och värdet som returneras av Value egenskapen är inte lika med parametern other .
|
Exempel
I följande kodexempel avgörs om ett objekt och ett Nullable<T> objekt är lika med det aktuella Nullable<T> objektet.
// This code example demonstrates the Nullable<T>.Equals
// methods.
using System;
class Sample
{
public static void Main()
{
int? nullInt1 = 100;
int? nullInt2 = 200;
object myObj;
// Determine if two nullable of System.Int32 values are equal.
// The nullable objects have different values.
Console.Write("1) nullInt1 and nullInt2 ");
if (nullInt1.Equals(nullInt2))
Console.Write("are");
else
Console.Write("are not");
Console.WriteLine(" equal.");
// Determine if a nullable of System.Int32 and an object
// are equal. The object contains the boxed value of the
// nullable object.
myObj = (object)nullInt1;
Console.Write("2) nullInt1 and myObj ");
if (nullInt1.Equals(myObj))
Console.Write("are");
else
Console.Write("are not");
Console.WriteLine(" equal.");
}
}
/*
This code example produces the following results:
1) nullInt1 and nullInt2 are not equal.
2) nullInt1 and myObj are equal.
*/
// This code example demonstrates the Nullable<T>.Equals
// methods.
open System
let nullInt1 = Nullable 100
let nullInt2 = Nullable 200
// Determine if two nullable of System.Int32 values are equal.
// The nullable objects have different values.
printf "1) nullInt1 and nullInt2 "
if nullInt1.Equals nullInt1 then
printf "are"
else
printf "are not"
printfn " equal."
// Determine if a nullable of System.Int32 and an object
// are equal. The object contains the boxed value of the
// nullable object.
let myObj = box nullInt1
printf "2) nullInt1 and myObj "
if nullInt1.Equals myObj then
printf "are"
else
printf "are not"
printfn " equal."
// This code example produces the following results:
// 1) nullInt1 and nullInt2 are not equal.
// 2) nullInt1 and myObj are equal.
' This code example demonstrates the Nullable(Of T).Equals
' methods.
Class Sample
Public Shared Sub Main()
Dim nullInt1 As Nullable(Of Integer) = 100
Dim nullInt2 As Nullable(Of Integer) = 200
Dim myObj As Object
' Determine if two nullable of System.Int32 values are equal.
' The nullable objects have different values.
Console.Write("1) nullInt1 and nullInt2 ")
If nullInt1.Equals(nullInt2) Then
Console.Write("are")
Else
Console.Write("are not")
End If
Console.WriteLine(" equal.")
' Determine if a nullable of System.Int32 and an object
' are equal. The object contains the boxed value of the
' nullable object.
myObj = CType(nullInt1, Object)
Console.Write("2) nullInt1 and myObj ")
If nullInt1.Equals(myObj) Then
Console.Write("are")
Else
Console.Write("are not")
End If
Console.WriteLine(" equal.")
End Sub
End Class
'
'This code example produces the following results:
'
'1) nullInt1 and nullInt2 are not equal.
'2) nullInt1 and myObj are equal.
'
Kommentarer
Om egenskapen för HasValue den aktuella Nullable<T> strukturen är true och other argumentet inte nullär , bestäms likheten genom att parametern otherEquals skickas till metoden för det underliggande värdet för den aktuella Nullable<T> strukturen.