Is there an error in TimeSpan?

This will print "0":

TimeSpan span = TimeSpan.Zero; span.Add(TimeSpan.FromMinutes(5)); Console.WriteLine(span.TotalSeconds); -----> 

However, this will output "300":

 TimeSpan span = TimeSpan.Zero.Add(TimeSpan.FromMinutes(5)); Console.WriteLine(span.TotalSeconds); -----> 

Is this a known bug?

+4
source share
2 answers

TimeSpan.Add does not change the input - it returns a new TimeSpan , which is the input plus the addition:

Notes

The return value must be between TimeSpan.MinValue and TimeSpan.MaxValue; otherwise an exception.

The return value is the new TimeSpan; The original TimeSpan is not changed.

+17
source

Not an error in Timespan, but .... in the way structures are copied to C #.

-3
source

All Articles