다음을 통해 공유


Decimal.Add 메서드

지정된 두 개의 Decimal 값을 추가합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Shared Function Add ( _
    d1 As Decimal, _
    d2 As Decimal _
) As Decimal
‘사용 방법
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

매개 변수

  • d2
    Decimal입니다.

반환 값

d1과 d2의 합인 Decimal 값입니다.

예외

예외 형식 조건

OverflowException

d1과 d2의 합이 MinValue보다 작거나 MaxValue보다 큰 경우

설명

다음 코드 예제에서는 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";
    }
}

플랫폼

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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Decimal 구조체
Decimal 멤버
System 네임스페이스
Subtract
Multiply
Divide