Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeSpan vs Duration

Tags:

c#

time

After reading the MSDN pages for the Timespan struct and the Duration struct,
I must admit that I am still not sure what is the difference between them.

Furthermore, the Duration struct contains a Duration(TimeSpan) Ctor,
which makes them even more similar.

So can anyone please tell me when each of them should be used?

Timespan struct:
https://msdn.microsoft.com/en-us/library/system.timespan.aspx

Duration struct:
https://msdn.microsoft.com/en-us/library/system.windows.duration.aspx

like image 968
spaceman Avatar asked Dec 21 '15 13:12

spaceman


1 Answers

You probably want to use TimeSpan.

TimeSpan is a generic data structure in the System namespace. Duration is a specialized structure for WPF animations. The description of Duration sums it up pretty well:

Represents the duration of time that a Timeline is active.

If you want to do exactly that (define the duration of a WPF animation timeline), use Duration. Otherwise, use TimeSpan.

like image 97
Heinzi Avatar answered Oct 19 '22 08:10

Heinzi