Freigeben über


Decimal.Add-Methode

Addiert zwei angegebene Decimal-Werte.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared Function Add ( _
    d1 As Decimal, _
    d2 As Decimal _
) As Decimal
'Usage
Dim d1 As Decimal
Dim d2 As Decimal
Dim returnValue As Decimal

returnValue = Decimal.Add(d1, d2)
public static decimal Add (
    decimal d1,
    decimal d2
)
public:
static Decimal Add (
    Decimal d1, 
    Decimal d2
)
public static Decimal Add (
    Decimal d1, 
    Decimal d2
)
public static function Add (
    d1 : decimal, 
    d2 : decimal
) : decimal

Parameter

  • d2
    Ein Decimal.

Rückgabewert

Ein Decimal-Wert, der die Summe von d1 und d2 darstellt.

Ausnahmen

Ausnahmetyp Bedingung

OverflowException

Die Summe von d1 und d2 ist kleiner als MinValue oder größer als MaxValue.

Hinweise

Das folgende Codebeispiel veranschaulicht die Verwendung von Add.

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
class PiggyBank {
    public void AddPenny() {
        MyFortune = Decimal.Add(MyFortune, .01m);
    }

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

    protected decimal MyFortune;
}
   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 = System.Decimal.Add(myFortune, 
            System.Convert.ToDecimal(0.01));
    } //AddPenny

    public String ToString()
    {
        return myFortune.ToString("C") + " in piggy bank";
    } //ToString

    protected System.Decimal myFortune;
} //PiggyBank
class PiggyBank {
    protected var MyFortune : Decimal;

    public function AddPenny() {
        MyFortune = Decimal.Add(MyFortune, 0.01);
    }

    public function ToString() : String {
        return MyFortune.ToString("C")+" in piggy bank";
    }
}

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

Decimal-Struktur
Decimal-Member
System-Namespace
Subtract
Multiply
Divide