Mega Code Archive

 
Categories / C# / Date Time
 

Example of the TimeSpan relational operators

using System; class TSRelationalOpsDemo {     const string dataFmt = "{0,34}    {1}" ;     static void CompareTimeSpans( TimeSpan Left, TimeSpan Right, string RightText )     {         Console.WriteLine( dataFmt, "Right: " + RightText, Right );         Console.WriteLine( dataFmt, "Left == Right", Left == Right );         Console.WriteLine( dataFmt, "Left >  Right", Left > Right );         Console.WriteLine( dataFmt, "Left >= Right", Left >= Right );         Console.WriteLine( dataFmt, "Left != Right", Left != Right );         Console.WriteLine( dataFmt, "Left <  Right", Left < Right );         Console.WriteLine( dataFmt, "Left <= Right", Left <= Right );     }     static void Main( )     {         TimeSpan Left = new TimeSpan( 2, 0, 0 );         CompareTimeSpans( Left, new TimeSpan( 0, 120, 0 ), "TimeSpan( 0, 120, 0 )" );     }  }