Search code examples
c#timespan

In C#, what would a Timespan.FromSeconds(-1) mean when used in a comparison?


Some code I was reading recently did a time calculation something like:

if (TimeWhenResponseArrived - TimeWhenRequested > Timespan.FromSeconds(-1))

I am having a hard time understanding what is trying to be done here. Are they subtracting the times and basically trying to see if they are less than 1 second apart?


Solution

  • Subtracting one DateTime variable from another one will return you a TimeSpan typed result. The code compares the result to decide if the difference is more than a second.