DateTimeOffset.Compare(DateTimeOffset, DateTimeOffset) Method is used to compare two DateTimeOffset objects and shows whether the first is earlier than the second, equal to the second, or later than the second.
Syntax: public static int Compare (DateTimeOffset first, DateTimeOffset second);
first: It is the first object to compare.
second: It is the second object to compare.
Return Value: This method returns a signed integer that indicates whether the value of the first parameter is earlier than, later than or the same time as the value of the second parameter.
- Less than zero: Means first is earlier than second.
- Zero: Means first is equal to second.
- Greater than zero: Means first is later than second.
Below programs illustrate the use of DateTimeOffset.Compare(DateTimeOffset, DateTimeOffset) Method:
offset1 is later than offset2
Example 2: For ArgumentOutOfRangeException
offset1 is equal to offset2
- Difference between Method Overriding and Method Hiding in C#
- C# | IndexOfAny() Method
- C# | Uri.GetHashCode() Method
- Stack.Contains() Method in C#
- C# | CompareOrdinal() Method
- C# | Math.Log() Method
- C# | Uri.IsHexDigit() Method
- C# | Random.Next() Method
- C# | Uri.FromHex() Method
- C# | Uri.IsBaseOf(Uri) Method
- C# | Method Overriding
- Method Hiding in C#
- C# | Clone() Method
- TimeSpan.Add() Method in C#
- C# | Insert() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.