DateTime.Equals Methode

Definitie

Retourneert een waarde die aangeeft of twee DateTime objecten, of een DateTime exemplaar en een ander object, DateTimedezelfde waarde hebben.

Overloads

Name Description
Equals(DateTime)

Retourneert een waarde die aangeeft of de waarde van dit exemplaar gelijk is aan de waarde van het opgegeven DateTime exemplaar.

Equals(Object)

Retourneert een waarde die aangeeft of dit exemplaar gelijk is aan een opgegeven object.

Equals(DateTime, DateTime)

Retourneert een waarde die aangeeft of twee DateTime exemplaren dezelfde datum- en tijdwaarde hebben.

Equals(DateTime)

Bron:
DateTime.cs
Bron:
DateTime.cs
Bron:
DateTime.cs
Bron:
DateTime.cs
Bron:
DateTime.cs

Retourneert een waarde die aangeeft of de waarde van dit exemplaar gelijk is aan de waarde van het opgegeven DateTime exemplaar.

public:
 virtual bool Equals(DateTime value);
public bool Equals(DateTime value);
override this.Equals : DateTime -> bool
Public Function Equals (value As DateTime) As Boolean

Parameters

value
DateTime

Het object dat moet worden vergeleken met dit exemplaar.

Retouren

trueals de value parameter gelijk is aan de waarde van dit exemplaar; anders. false

Implementeringen

Voorbeelden

In het volgende voorbeeld ziet u de Equals methode.

using System;

public class Application
{
    public static void Main()
    {
        // Create some DateTime objects.
        DateTime one = DateTime.UtcNow;

        DateTime two = DateTime.Now;

        DateTime three = one;

        // Compare the DateTime objects and display the results.
        bool result = one.Equals(two);

        Console.WriteLine("The result of comparing DateTime object one and two is: {0}.", result);

        result = one.Equals(three);

        Console.WriteLine("The result of comparing DateTime object one and three is: {0}.", result);
    }
}

// This code example displays the following:
//
// The result of comparing DateTime object one and two is: False.
// The result of comparing DateTime object one and three is: True.
open System

// Create some DateTime objects.
let one = DateTime.UtcNow

let two = DateTime.Now

let three = one

// Compare the DateTime objects and display the results.
let result = one.Equals two

printfn $"The result of comparing DateTime object one and two is: {result}."

let result2 = one.Equals three

printfn $"The result of comparing DateTime object one and three is: {result2}."

// This code example displays the following:
//
// The result of comparing DateTime object one and two is: False.
// The result of comparing DateTime object one and three is: True.
Module Application

    Sub Main()
        ' Create some DateTime objects.
        Dim one As DateTime = DateTime.UtcNow

        Dim two As DateTime = DateTime.Now

        Dim three As DateTime = one

        ' Compare the DateTime objects and display the results.
        Dim result As Boolean = one.Equals(two)

        Console.WriteLine("The result of comparing DateTime object one and two is: {0}.", result)

        result = one.Equals(three)

        Console.WriteLine("The result of comparing DateTime object one and three is: {0}.", result)

    End Sub
End Module

' This code example displays the following:
'
' The result of comparing DateTime object one and two is: False.
' The result of comparing DateTime object one and three is: True.

Opmerkingen

Het huidige exemplaar en value zijn gelijk als de Ticks eigenschapswaarden gelijk zijn. Hun Kind eigenschapswaarden worden niet meegenomen in de test voor gelijkheid.

Deze methode implementeert de System.IEquatable<T> interface en presteert iets beter dan de Equals methode omdat de value parameter niet hoeft te worden geconverteerd naar een object.

Zie ook

Van toepassing op

Equals(Object)

Bron:
DateTime.cs
Bron:
DateTime.cs
Bron:
DateTime.cs
Bron:
DateTime.cs
Bron:
DateTime.cs

Retourneert een waarde die aangeeft of dit exemplaar gelijk is aan een opgegeven object.

public:
 override bool Equals(System::Object ^ value);
public override bool Equals(object value);
public override bool Equals(object? value);
override this.Equals : obj -> bool
Public Overrides Function Equals (value As Object) As Boolean

Parameters

value
Object

Het object dat moet worden vergeleken met dit exemplaar.

Retouren

trueals value dit een instantie is van DateTime en gelijk is aan de waarde van dit exemplaar; anders. false

Voorbeelden

In het volgende voorbeeld ziet u de Equals methode.

using System;

public class Application
{
    public static void Main()
    {
        // Create some DateTime objects.
        DateTime one = DateTime.UtcNow;

        DateTime two = DateTime.Now;

        DateTime three = one;

        // Compare the DateTime objects and display the results.
        bool result = one.Equals(two);

        Console.WriteLine("The result of comparing DateTime object one and two is: {0}.", result);

        result = one.Equals(three);

        Console.WriteLine("The result of comparing DateTime object one and three is: {0}.", result);
    }
}

// This code example displays the following:
//
// The result of comparing DateTime object one and two is: False.
// The result of comparing DateTime object one and three is: True.
open System

// Create some DateTime objects.
let one = DateTime.UtcNow

let two = DateTime.Now

let three = one

// Compare the DateTime objects and display the results.
let result = one.Equals two

printfn $"The result of comparing DateTime object one and two is: {result}."

let result2 = one.Equals three

printfn $"The result of comparing DateTime object one and three is: {result2}."

// This code example displays the following:
//
// The result of comparing DateTime object one and two is: False.
// The result of comparing DateTime object one and three is: True.
Module Application

    Sub Main()
        ' Create some DateTime objects.
        Dim one As DateTime = DateTime.UtcNow

        Dim two As DateTime = DateTime.Now

        Dim three As DateTime = one

        ' Compare the DateTime objects and display the results.
        Dim result As Boolean = one.Equals(two)

        Console.WriteLine("The result of comparing DateTime object one and two is: {0}.", result)

        result = one.Equals(three)

        Console.WriteLine("The result of comparing DateTime object one and three is: {0}.", result)

    End Sub
End Module

' This code example displays the following:
'
' The result of comparing DateTime object one and two is: False.
' The result of comparing DateTime object one and three is: True.

Opmerkingen

Het huidige exemplaar en value zijn gelijk als de Ticks eigenschapswaarden gelijk zijn. Hun Kind eigenschapswaarden worden niet meegenomen in de test voor gelijkheid.

Zie ook

Van toepassing op

Equals(DateTime, DateTime)

Bron:
DateTime.cs
Bron:
DateTime.cs
Bron:
DateTime.cs
Bron:
DateTime.cs
Bron:
DateTime.cs

Retourneert een waarde die aangeeft of twee DateTime exemplaren dezelfde datum- en tijdwaarde hebben.

public:
 static bool Equals(DateTime t1, DateTime t2);
public static bool Equals(DateTime t1, DateTime t2);
static member Equals : DateTime * DateTime -> bool
Public Shared Function Equals (t1 As DateTime, t2 As DateTime) As Boolean

Parameters

t1
DateTime

Het eerste object dat moet worden vergeleken.

t2
DateTime

Het tweede object dat moet worden vergeleken.

Retouren

true als de twee waarden gelijk zijn; anders, false.

Voorbeelden

In het volgende voorbeeld ziet u de Equals methode.

let today1 = 
    System.DateTime System.DateTime.Today.Ticks

let today2 =
    System.DateTime System.DateTime.Today.Ticks

let tomorrow =
    System.DateTime.Today.AddDays(1).Ticks
    |> System.DateTime 

// todayEqualsToday gets true.
let todayEqualsToday = System.DateTime.Equals(today1, today2)

// todayEqualsTomorrow gets false.
let todayEqualsTomorrow = System.DateTime.Equals(today1, tomorrow)
System.DateTime today1 =
        new System.DateTime(System.DateTime.Today.Ticks);
System.DateTime today2 =
        new System.DateTime(System.DateTime.Today.Ticks);
System.DateTime tomorrow =
        new System.DateTime(
                    System.DateTime.Today.AddDays(1).Ticks);

// todayEqualsToday gets true.
bool todayEqualsToday = System.DateTime.Equals(today1, today2);

// todayEqualsTomorrow gets false.
bool todayEqualsTomorrow = System.DateTime.Equals(today1, tomorrow);
Dim today1 As New System.DateTime(System.DateTime.Today.Ticks)
Dim today2 As New System.DateTime(System.DateTime.Today.Ticks)
Dim tomorrow As New System.DateTime( _
                        System.DateTime.Today.AddDays(1).Ticks)

' todayEqualsToday gets true.
Dim todayEqualsToday As Boolean = System.DateTime.Equals(today1, today2)

' todayEqualsTomorrow gets false.
Dim todayEqualsTomorrow As Boolean = System.DateTime.Equals(today1, tomorrow)

Opmerkingen

t1 en t2 zijn gelijk als de Ticks eigenschapswaarden gelijk zijn. Hun Kind eigenschapswaarden worden niet meegenomen in de test voor gelijkheid.

Zie ook

Van toepassing op