語言

Decimal.Add(Decimal, Decimal) 方法

定義

加兩個指定 Decimal 值。

public:
 static System::Decimal Add(System::Decimal d1, System::Decimal d2);
public static decimal Add(decimal d1, decimal d2);
static member Add : decimal * decimal -> decimal
Public Shared Function Add (d1 As Decimal, d2 As Decimal) As Decimal

參數

d1
Decimal

這是第一個要補充的價值。

d2
Decimal

第二個值得加的價值。

傳回

d1 和 d2 的總和。

例外狀況

與 d1 的d2和小於 Decimal.MinValue 或大於 Decimal.MaxValue。

備註

以下程式碼範例說明了以下的 Add 使用:

class PiggyBank {
    public void AddPenny() {
        MyFortune = Decimal.Add(MyFortune, .01m);
    }

    public override string ToString() {
        return MyFortune.ToString("C")+" in piggy bank";
    }

    protected decimal MyFortune;
}
type PiggyBank() =
    let mutable myFortune = 0m

    member _.AddPenny() =
        myFortune <- Decimal.Add(myFortune, 0.01m)

    override _.ToString() =
        $"{myFortune:C} in piggy bank"
Class PiggyBank

    Public Sub AddPenny()
        MyFortune = [Decimal].Add(MyFortune, 0.01D)
    End Sub

    Public Overrides Function ToString() As String
        Return MyFortune.ToString("C") + " in piggy bank"
    End Function

    Protected MyFortune As Decimal
End Class

適用於

另請參閱