C# TimeSpan CompareTo(TimeSpan)

Description

TimeSpan CompareTo(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.

Syntax

TimeSpan.CompareTo(TimeSpan) has the following syntax.


public int CompareTo(
  TimeSpan value
)

Parameters

TimeSpan.CompareTo(TimeSpan) has the following parameters.

  • value - An object to compare to this instance.

Returns

TimeSpan.CompareTo(TimeSpan) method returns A signed number indicating the relative values of this instance and value. Value Description A negative integer This instance is shorter than value. Zero This instance is equal to value. A positive integer This instance is longer than value.

Example

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


/* w  w w  .  j a  v  a2s.  c o m*/
using System;

class Sample 
{
    public static void Main() 
    {
        TimeSpan  tsX = new TimeSpan(11, 22, 33, 44); 
        TimeSpan  ts = new TimeSpan(11, 22, 33, 45); 
        Console.WriteLine(tsX.CompareTo(ts));
    }
}

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