Saturday, December 22, 2007

TimeSpan.Seconds vs .TotalSeconds

The difference between the Seconds property and the TotalSeconds property is (or at least should be) pretty obvious, but based on experience it is a common bug to use .Seconds when you actually mean .TotalSeconds. For the readers out there that hasn't gotten the difference, think of a timespan of value 1 minute 23 seconds - here .Seconds is 23 and total seconds is 83.

As a rule of thumb, most often it's the Total variant you want, and yes, the same applies to all the other members too, (e.g. .Minutes, .Milliseconds vs. the corresponding .Total-prefixed ones)

No comments: