TimeSpan 具有以下构造函数。
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;
}
internal static long TimeToTicks(int hour, int minute, int second)
{
long num = (long)hour * 3600L + (long)minute * 60L + (long)second;
if (num > 922337203685L || num < -922337203685L)
{
throw new ArgumentOutOfRangeException(null, Environment.GetResourceString("Overflow_TimeSpanTooLong"));
}
return num * 10000000L;
}
我认为 TimeToTicks 只是最后一个构造函数的简化版本。
为什么第一个不使用this = new TimeSpan(0, hours, minutes, seconds, 0);
?