C# DateTimeOffset Inequality

Description

DateTimeOffset Inequality determines whether two specified DateTimeOffset objects refer to different points in time.

Syntax

DateTimeOffset.Inequality has the following syntax.


public static bool operator !=(
  DateTimeOffset left,
  DateTimeOffset right
)

Parameters

DateTimeOffset.Inequality has the following parameters.

  • left - The first object to compare.
  • right - The second object to compare.

Returns

DateTimeOffset.Inequality method returns true if left and right do not have the same UtcDateTime value; otherwise, false.

Example

The Inequality method defines the operation of the inequality operator for DateTimeOffset objects. It always returns the opposite result from Equality. The Inequality method enables code such as the following:


using System;/*from  ww w .  j  av a  2s  . com*/
public class MainClass{
  public static void Main(String[] argv){  
    DateTimeOffset date1 = new DateTimeOffset(2007, 6, 3, 14, 45, 0, 
                 new TimeSpan(-7, 0, 0));
    DateTimeOffset date2 = new DateTimeOffset(2007, 6, 3, 15, 45, 0,
                 new TimeSpan(-6, 0, 0));
    DateTimeOffset date3 = new DateTimeOffset(date1.DateTime, 
                 new TimeSpan(-6, 0, 0));
    Console.WriteLine(date1 != date2);        // Displays False
    Console.WriteLine(date1 != date3);        // Displays True

  }
}
    

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