TimeSpan.Addition(TimeSpan, TimeSpan) 運算子

定義

加入兩個指定的 TimeSpan 執行個體。Adds two specified TimeSpan instances.

public:
 static TimeSpan operator +(TimeSpan t1, TimeSpan t2);
public static TimeSpan operator + (TimeSpan t1, TimeSpan t2);
static member ( + ) : TimeSpan * TimeSpan -> TimeSpan
Public Shared Operator + (t1 As TimeSpan, t2 As TimeSpan) As TimeSpan

參數

t1
TimeSpan

要加入的第一個時間間隔。The first time interval to add.

t2
TimeSpan

要加入的第二個時間間隔。The second time interval to add.

傳回

TimeSpan

物件,其值為 t1t2 值的總和。An object whose value is the sum of the values of t1 and t2.

例外狀況

產生的 TimeSpan 小於 MinValue 或大於 MaxValueThe resulting TimeSpan is less than MinValue or greater than MaxValue.

備註

Addition方法會定義值的加法運算子 TimeSpanThe Addition method defines the addition operator for TimeSpan values. 它會啟用如下的程式碼:It enables code such as the following:

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("  {0,12}\n +  {1,10}\n   {3}\n    {2,10}", 
                  time1, time2, time3, new String('_', 10));

// The example displays the following output:
//           1.00:00:00
//        +    12:00:00
//          __________
//           1.12:00:00
Dim time1 As New TimeSpan(1, 0, 0, 0)   ' TimeSpan equivalent to 1 day.
Dim time2 As New TimeSpan(12, 0, 0)     ' TimeSpan equivalent to 1/2 day.
Dim time3 As TimeSpan = time1 + time2   ' Add the two time spans.

Console.WriteLine("  {0,12}{3} +  {1,10}{3}   {4}{3}    {2,10}", _
                  time1, time2, time3, vbCrLf, New String("_"c, 10))
' The example displays the following output:
'           1.00:00:00
'        +    12:00:00
'          __________
'           1.12:00:00

不支援自訂運算子的語言可以改為呼叫 Add 方法。Languages that do not support custom operators can call the Add method instead.

這個運算子的對等方法是 TimeSpan.Add(TimeSpan)The equivalent method for this operator is TimeSpan.Add(TimeSpan)

適用於

另請參閱