C# DateTime Equals(Object)

Description

DateTime Equals(Object) returns a value indicating whether this instance is equal to a specified object.

Syntax

DateTime.Equals(Object) has the following syntax.


public override bool Equals(
  Object value
)

Parameters

DateTime.Equals(Object) has the following parameters.

  • value - The object to compare to this instance.

Returns

DateTime.Equals(Object) method returns true if value is an instance of DateTime and equals the value of this instance; otherwise, false.

Example

The following example demonstrates the Equals method.


//from w  w w .  ja  v a 2  s . c  om
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);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version