Sunday, 18 August 2013

Why does TimeSpan use duplicated TimeToTicks?

Why does TimeSpan use duplicated TimeToTicks?

TimeSpan has following constructors.
public TimeSpan(int hours, int minutes, int seconds)
{
this._ticks = TimeSpan.TimeToTicks(hours, minutes, seconds);
}
public TimeSpan(int days, int hours, int minutes, int seconds)
{
this = new TimeSpan(days, hours, minutes, seconds, 0);
}
public TimeSpan(int days, int hours, int minutes, int seconds, int
milliseconds)
{
long num = ((long)days * 3600L * 24L + (long)hours * 3600L +
(long)minutes * 60L + (long)seconds) * 1000L + (long)milliseconds;
if (num > 922337203685477L || num < -922337203685477L)
{
throw new ArgumentOutOfRangeException(null,
Environment.GetResourceString("Overflow_TimeSpanTooLong"));
}
this._ticks = num * 10000L;
}
I think TimeToTicks is just a simplification version of the last constructor.
Why does the first one not use this = new TimeSpan(days, hours, minutes,
seconds, 0);?

No comments:

Post a Comment