TimeSpan.CompareTo Method (TimeSpan)


Compares this instance to a specified TimeSpan object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the TimeSpan object.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

abstract CompareTo : 
        value:TimeSpan -> int
override CompareTo : 
        value:TimeSpan -> int


Type: System.TimeSpan

An object to compare to this instance.

Return Value

Type: System.Int32

A signed number indicating the relative values of this instance and value.



A negative integer

This instance is shorter than value.


This instance is equal to value.

A positive integer

This instance is longer than value.

This method implements the System.IComparable<'T> interface and performs slightly better than the TimeSpan.CompareTo method because it does not have to convert the value parameter to an object.

The following example demonstrates generic and nongeneric versions of the CompareTo method for several value and reference types.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top