userSteve userSteve - 1 year ago 98
C# Question

Is there a difference between these TimeSpan methods?

Are these statements syntactically the same and perform the same ?
Which is preferable?

TimeSpan ts = TimeSpan.FromTicks(100000);


or

TimeSpan ts = new TimeSpan(100000);

Answer Source

There is no difference between them. The static method initialize new instance using the following constructor.

TimeSpan(Int64) which initializes a new instance of the TimeSpan structure to the specified number of ticks.

[__DynamicallyInvokable]
public static TimeSpan FromTicks(long value)
{
    return new TimeSpan(value);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download