Compare two TimeSpan values in CSharp

Description

The following code shows how to compare two TimeSpan values.

Example


//from  ww w . j a v a2  s. co m
using System;

class Example
{
    static void Main()
    {
        // Define a time interval equal to two hours.
        TimeSpan baseInterval = new TimeSpan( 2, 0, 0);

        TimeSpan span = TimeSpan.FromSeconds(-2.5);

        int result = TimeSpan.Compare(baseInterval, span);
        Console.WriteLine(result);     
    } 
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var