This documentation is archived and is not being maintained.

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.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.