System.TimeSpan.Add Method

Returns a new TimeSpan object whose value is the sum of the specified TimeSpan object and this instance.

Syntax

public TimeSpan Add (TimeSpan ts)

Parameters

ts
The time interval to add.

Returns

A new object that represents the value of this instance plus the value of ts.

Exceptions

TypeReason
OverflowExceptionThe sum of the value of the current instance and the value of ts is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue.

Remarks

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

The return value is a new TimeSpan; the original TimeSpan is not modified.

Example

This example demonstrates the TimeSpan.Add(TimeSpan) method.

C# Example

using System;
public class TimeSpanAddExample {
   public static void Main() {
      TimeSpan ts = new TimeSpan(Int32.MaxValue);
      Console.WriteLine("The value of the timespan 'ts' is {0}", ts);
      Console.WriteLine("ts.Add(ts) = {0}", ts.Add(ts));
   }
}

The output is

The value of the timespan 'ts' is 00:03:34.7483647
ts.Add(ts) = 00:07:09.4967294

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0