Condividi tramite


DateTime.Equals Metodo

Definizione

Restituisce un valore che indica se due DateTime oggetti, o un'istanza DateTime e un altro oggetto o DateTime, hanno lo stesso valore.

Overload

Nome Descrizione
Equals(DateTime)

Restituisce un valore che indica se il valore di questa istanza è uguale al valore dell'istanza specificata DateTime .

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

Equals(DateTime, DateTime)

Restituisce un valore che indica se due DateTime istanze hanno lo stesso valore di data e ora.

Equals(DateTime)

Origine:
DateTime.cs
Origine:
DateTime.cs
Origine:
DateTime.cs
Origine:
DateTime.cs
Origine:
DateTime.cs

Restituisce un valore che indica se il valore di questa istanza è uguale al valore dell'istanza specificata DateTime .

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

Parametri

value
DateTime

Oggetto da confrontare con questa istanza.

Restituisce

true se il value parametro è uguale al valore di questa istanza; in caso contrario, false.

Implementazioni

Esempio

Nell'esempio seguente viene illustrato il Equals metodo .

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.

Commenti

L'istanza corrente e value sono uguali se i valori Ticks delle proprietà sono uguali. I valori Kind delle proprietà non vengono considerati nel test per verificarne l'uguaglianza.

Questo metodo implementa l'interfaccia System.IEquatable<T> ed esegue prestazioni leggermente migliori rispetto al Equals metodo perché il value parametro non deve essere convertito in un oggetto .

Vedi anche

Si applica a

Equals(Object)

Origine:
DateTime.cs
Origine:
DateTime.cs
Origine:
DateTime.cs
Origine:
DateTime.cs
Origine:
DateTime.cs

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

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

Parametri

value
Object

Oggetto da confrontare con questa istanza.

Restituisce

true se value è un'istanza di DateTime e è uguale al valore di questa istanza; in caso contrario, false.

Esempio

Nell'esempio seguente viene illustrato il Equals metodo .

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.

Commenti

L'istanza corrente e value sono uguali se i valori Ticks delle proprietà sono uguali. I valori Kind delle proprietà non vengono considerati nel test per verificarne l'uguaglianza.

Vedi anche

Si applica a

Equals(DateTime, DateTime)

Origine:
DateTime.cs
Origine:
DateTime.cs
Origine:
DateTime.cs
Origine:
DateTime.cs
Origine:
DateTime.cs

Restituisce un valore che indica se due DateTime istanze hanno lo stesso valore di data e ora.

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

Parametri

t1
DateTime

Primo oggetto da confrontare.

t2
DateTime

Secondo oggetto da confrontare.

Restituisce

true se i due valori sono uguali; in caso contrario, false.

Esempio

Nell'esempio seguente viene illustrato il Equals metodo .

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)

Commenti

t1 e t2 sono uguali se i valori Ticks delle proprietà sono uguali. I valori Kind delle proprietà non vengono considerati nel test per verificarne l'uguaglianza.

Vedi anche

Si applica a