This documentation is archived and is not being maintained.

Decimal.Add Method

Adds two specified Decimal values.

[Visual Basic]
Public Shared Function Add( _
   ByVal d1 As Decimal, _
   ByVal d2 As Decimal _
) As Decimal
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;


A Decimal.
A Decimal.

Return Value

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


Exception Type Condition
OverflowException The sum of d1 and d2 is less than MinValue or greater than MaxValue.


The following code sample illustrates the use of Add:

[Visual Basic] 
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 __gc class PiggyBank {
    void AddPenny() {
        MyFortune = Decimal::Add(MyFortune, .01);

    System::String* ToString() {
        return String::Concat(MyFortune.ToString("C"),S" in piggy bank");

    Decimal MyFortune;

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


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Decimal Structure | Decimal Members | System Namespace | Subtract | Multiply | Divide