DateTime.Equality(DateTime, DateTime) Operator

Definicja

Określa, czy dwa określone wystąpienia adresu DateTime są takie same.

public:
 static bool operator ==(DateTime d1, DateTime d2);
public static bool operator == (DateTime d1, DateTime d2);
static member ( = ) : DateTime * DateTime -> bool
Public Shared Operator == (d1 As DateTime, d2 As DateTime) As Boolean

Parametry

d1
DateTime

Pierwszy obiekt do porównania.

d2
DateTime

Drugi obiekt do porównania.

Zwraca

Boolean

true jeśli d1 i d2 reprezentuje tę samą datę i godzinę; w przeciwnym razie false.

Przykłady

W poniższym przykładzie pokazano operator równości.

System::DateTime april19( 2001, 4, 19 );
System::DateTime otherDate( 1991, 6, 5 );

// areEqual gets false.
bool areEqual = april19 == otherDate;

otherDate = DateTime( 2001, 4, 19 );
// areEqual gets true.
areEqual = april19 == otherDate;
let april19 = DateTime(2001, 4, 19)
let otherDate = DateTime(1991, 6, 5)

// areEqual gets false.
let areEqual = april19 = otherDate

let otherDate = DateTime(2001, 4, 19)
// areEqual gets true.
let areEqual = april19 = otherDate
System.DateTime april19 = new DateTime(2001, 4, 19);
System.DateTime otherDate = new DateTime(1991, 6, 5);

// areEqual gets false.
bool areEqual = april19 == otherDate;
    
otherDate = new DateTime(2001, 4, 19);
// areEqual gets true.
areEqual = april19 == otherDate;
Dim april19 As New DateTime(2001, 4, 19)
Dim otherDate As New DateTime(1991, 6, 5)

Dim areEqual As Boolean
' areEqual gets false.
areEqual = DateTime.op_Equality(april19, otherDate)

otherDate = New DateTime(2001, 4, 19)
' areEqual gets true.
areEqual = System.DateTime.op_Equality(april19, otherDate)

Uwagi

Operator Equality określa, czy dwie DateTime wartości są równe, porównując ich liczbę kleszczy. Przed porównaniem DateTime obiektów upewnij się, że obiekty reprezentują czasy w tej samej strefie czasowej. Można to zrobić, porównując wartości ich Kind właściwości.

Równoważną metodą dla tego operatora jest DateTime.Equals(Object)

Dotyczy

Zobacz też