C# TimeSpan Compare
Description
TimeSpan Compare
compares two TimeSpan values and returns
an integer that indicates whether the first value is shorter than, equal
to, or longer than the second value.
Syntax
TimeSpan.Compare
has the following syntax.
public static int Compare(
TimeSpan t1,
TimeSpan t2
)
Parameters
TimeSpan.Compare
has the following parameters.
t1
- The first time interval to compare.t2
- The second time interval to compare.
Returns
TimeSpan.Compare
method returns One of the following values. Value Description -1 t1 is shorter than t2. 0
t1 is equal to t2. 1 t1 is longer than t2.
Example
The following example uses the Compare method to compare TimeSpan objects with a TimeSpan object.
/* w w w. j av a 2 s. c o 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.