DateTime.Equals Yöntem

Tanım

İki DateTime nesnenin veya örneğin ve başka bir nesnenin veya öğesinin DateTimeaynı değere sahip olup olmadığını belirten bir DateTime değer döndürür.

Aşırı Yüklemeler

Equals(DateTime)

Bu örneğin değerinin belirtilen DateTime örneğin değerine eşit olup olmadığını belirten bir değer döndürür.

Equals(Object)

Bu örneğin, belirtilen bir nesneye eşit olup olmadığını gösteren bir değeri döndürür.

Equals(DateTime, DateTime)

İki DateTime örneğin aynı tarih ve saat değerine sahip olup olmadığını belirten bir değer döndürür.

Equals(DateTime)

Kaynak:
DateTime.cs
Kaynak:
DateTime.cs
Kaynak:
DateTime.cs

Bu örneğin değerinin belirtilen DateTime örneğin değerine eşit olup olmadığını belirten bir değer döndürür.

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

Parametreler

value
DateTime

Bu örnekle karşılaştıracak nesne.

Döndürülenler

truevalue parametresi bu örneğin değerine eşitse; değilse , false.

Uygulamalar

Örnekler

Aşağıdaki örnekte yöntemi gösterilmektedir Equals .

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.

Açıklamalar

Geçerli örnek ve value özellik değerleri eşitse Ticks eşittir. Özellik Kind değerleri eşitlik testinde dikkate alınmaz.

Bu yöntem arabirimini uygular ve parametresinin System.IEquatable<T>Equals bir nesneye dönüştürülmesi gerekmediğinden value yönteminden biraz daha iyi performans gösterir.

Ayrıca bkz.

Şunlara uygulanır

Equals(Object)

Kaynak:
DateTime.cs
Kaynak:
DateTime.cs
Kaynak:
DateTime.cs

Bu örneğin, belirtilen bir nesneye eşit olup olmadığını gösteren bir değeri döndürür.

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

Parametreler

value
Object

Bu örnekle karşılaştıracak nesne.

Döndürülenler

trueörneğiyse DateTime ve bu örneğin değerine eşitsevalue; değilse, false.

Örnekler

Aşağıdaki örnekte yöntemi gösterilmektedir Equals .

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.

Açıklamalar

Geçerli örnek ve value özellik değerleri eşitse Ticks eşittir. Özellik Kind değerleri eşitlik testinde dikkate alınmaz.

Ayrıca bkz.

Şunlara uygulanır

Equals(DateTime, DateTime)

Kaynak:
DateTime.cs
Kaynak:
DateTime.cs
Kaynak:
DateTime.cs

İki DateTime örneğin aynı tarih ve saat değerine sahip olup olmadığını belirten bir değer döndürür.

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

Parametreler

t1
DateTime

Karşılaştırma yapılacak ilk nesne.

t2
DateTime

Karşılaştırma yapılacak ikinci nesne.

Döndürülenler

true iki değer eşitse; aksi takdirde , false.

Örnekler

Aşağıdaki örnekte yöntemi gösterilmektedir Equals .

System::DateTime today1 = System::DateTime(
   System::DateTime::Today.Ticks );
System::DateTime today2 = System::DateTime(
   System::DateTime::Today.Ticks );
System::DateTime tomorrow = 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 );
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)

Açıklamalar

t1 ve t2 özellik değerleri eşitse Ticks eşittir. Özellik Kind değerleri eşitlik testinde dikkate alınmaz.

Ayrıca bkz.

Şunlara uygulanır