Decimal.Add(Decimal, Decimal) Decimal.Add(Decimal, Decimal) Decimal.Add(Decimal, Decimal) Decimal.Add(Decimal, Decimal) Method

定義

加入兩個指定的 Decimal 值。Adds two specified Decimal values.

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 Decimal Decimal Decimal

要相加的第一個值。The first value to add.

d2
Decimal Decimal Decimal Decimal

要相加的第二個值。The second value to add.

傳回

d1d2 的總和。The sum of d1 and d2.

例外狀況

d1d2 的總和小於 MinValue 或大於 MaxValueThe sum of d1 and d2 is less than MinValue or greater than MaxValue.

備註

下列程式碼範例說明如何使用AddThe following code sample illustrates the use of Add :

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

      virtual System::String^ ToString() override
      {
         return MyFortune.ToString("C")+" in piggy bank";
      }

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

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

    protected decimal MyFortune;
}
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

適用於

另請參閱