Sdílet prostřednictvím


Decimal.Add Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Adds two specified Decimal values.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Shared Function Add ( _
    d1 As Decimal, _
    d2 As Decimal _
) As Decimal
[SecuritySafeCriticalAttribute]
public static decimal Add(
    decimal d1,
    decimal d2
)

Parameters

Return Value

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

Exceptions

Exception Condition
OverflowException

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

Remarks

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

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.