共用方式為


TimeSpan.Addition(TimeSpan, TimeSpan) 運算子

定義

加入兩個指定的 TimeSpan 執行個體。

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

要加入的第一個時間間隔。

t2
TimeSpan

要加入的第二個時間間隔。

傳回

物件,其值為 t1t2 值的總和。

例外狀況

備註

方法 Addition 會定義值的加法運算子 TimeSpan 。 它會啟用下列程式碼:

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
open System

let time1 = TimeSpan(1, 0, 0, 0)   // TimeSpan equivalent to 1 day.
let time2 = TimeSpan(12, 0, 0)     // TimeSpan equivalent to 1/2 day.
let time3 = time1 + time2          // Add the two time spans.

printfn $"  {time1,12}\n +  {time2,10}\n   {String('_', 10)}\n    {time3,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 方法。

這個運算子的對等方法為 TimeSpan.Add(TimeSpan)

適用於

另請參閱