This documentation is archived and is not being maintained.

Decimal.Add Method

Adds two specified Decimal values.

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

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

Parameters

d1

A Decimal.

d2

A Decimal.

Return Value

A Decimal value that is the sum of d1 and d2.

Exception typeCondition

OverflowException

The sum of d1 and d2 is less than MinValue or greater than MaxValue.

The following code sample illustrates the use of 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;
}

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";
    }
}

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Show: