C# TimeSpan Addition

Description

TimeSpan Addition adds two specified TimeSpan instances.

Syntax

TimeSpan.Addition has the following syntax.


public static TimeSpan operator +(
  TimeSpan t1,
  TimeSpan t2
)

Parameters

TimeSpan.Addition has the following parameters.

  • t1 - The first time interval to add.
  • t2 - The second time interval to add.

Returns

TimeSpan.Addition method returns An object whose value is the sum of the values of t1 and t2.

Example

The Addition method defines the addition operator for TimeSpan values.


/*w  ww.jav a  2 s.  com*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    TimeSpan time1 = new TimeSpan(1, 0, 0, 0);   // TimeSpan equivalent to 1 day.
    TimeSpan time2 = new TimeSpan(12, 0, 0);     // TimeSpan equivalent to 1/2 day.
    TimeSpan time3 = time1 + time2;              // Add the two time spans.
    
    Console.WriteLine(time3);

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version