Home  |  Delphi .net Home  |  System.TimeSpan  |  Equals Method
  
Equals  
Method  
Returns true if TimeSpan values are exactly the same
TimeSpan Structure
System NameSpace
CF1.  Function Equals ( Target : Object ) : Boolean;
CF2.  Function Equals ( ValueA : TimeSpan; ValueB : TimeSpan ) : Boolean; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Syntax 1 compares the current (Source) TimeSpan value with the Target value :
 
Returns one of the following values :
 
Source < Target Gives <0
Source = Target Gives  0
Source > Target Gives >0

 
The Target parameter must be a TimeSpan object or a null reference. Quite why this parameter is not TimeSpan is not clear.
 
Syntax 2 compares ValueA with ValueB
 
Returns one of the following values :
 
ValueA < ValueB Gives <0
ValueA = ValueB Gives  0
ValueA > ValueB Gives >0

 
The exact value pf the result for both syntaxes is not guaranteed.
 
The time span must be exactly the same to the tick to give a 0 result. (A tick is 0.0000001 seconds).
Notes
Static methods are not methods of an object - they are simply class functions or procedures available at any time.
Microsoft MSDN Links
System
System.TimeSpan
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  span1, span2 : TimeSpan;
  result       : Integer;

begin
  span1 := TimeSpan.Create(1, 2, 30);  // 0 days, 1 hour, 2 mins, 30 secs
  span2 := TimeSpan.Create(1, 2, 31);  // 0 days, 1 hour, 2 mins, 31 secs

  Console.WriteLine('span1 = {0:F}', span1);
  Console.WriteLine('span2 = {0:F}', span2);

  if span1.Equals(span2)
  then Console.WriteLine('span1  = span2')
  else Console.WriteLine('span1 <> span2');

  Console.ReadLine;
end.
   span1 = 01:02:30
   span2 = 01:02:31
   span1 <> span2
Using the static method
program Project1;
{$APPTYPE CONSOLE}

var
  span1, span2 : TimeSpan;
  result       : Integer;

begin
  span1 := TimeSpan.Create(1, 2, 30);  // 0 days, 1 hour, 2 mins, 30 secs
  span2 := TimeSpan.Create(1, 2, 31);  // 0 days, 1 hour, 2 mins, 31 secs

  Console.WriteLine('span1 = {0:F}', span1);
  Console.WriteLine('span2 = {0:F}', span2);

  if System.TimeSpan.Equals(span1, span2)
  then Console.WriteLine('span1  = span2')
  else Console.WriteLine('span1 <> span2');

  Console.ReadLine;
end.
   span1 = 01:02:30
   span2 = 01:02:31
   span1 <> span2
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author