내보내기(0) 인쇄
모두 확장
정보
요청한 주제가 아래에 표시됩니다. 그러나 이 주제는 이 라이브러리에 포함되지 않습니다.

Decimal.Increment 연산자

2013-12-13

Decimal 피연산자를 1씩 증가시킵니다.

Namespace:  System
어셈블리:  mscorlib(mscorlib.dll)

public static decimal operator ++(
	decimal d
)

매개 변수

d
형식: System.Decimal
피연산자 Decimal입니다.

반환 값

형식: System.Decimal
1씩 증가된 d의 값입니다.

예외조건
OverflowException

반환 값이 MinValue보다 작거나 MaxValue보다 큰 경우

다음 코드 예제에서는 Increment 연산자를 몇 개의 Decimal 값에 적용합니다.


// Example of the decimal increment, decrement, unary negation, and 
// unary plus operators.
using System;

class Example
{
   // Get the exception type name; remove the namespace prefix.
   public static string GetExceptionType(Exception ex)
   {
      string exceptionType = ex.GetType().ToString();
      return exceptionType.Substring(
          exceptionType.LastIndexOf('.') + 1);
   }

   // Display the argument and the incremented and decremented values.
   public static void DecIncrDecrUnary(System.Windows.Controls.TextBlock outputBlock, decimal argument)
   {
      decimal toBeIncr = argument;
      decimal toBeDecr = argument;

      outputBlock.Text += String.Format("{0,-26}{1}", "decimal argument: ",
          argument) + "\n";

      // Catch the exception if the increment operator throws one.
      outputBlock.Text += String.Format("{0,-26}", "argument ++");
      try
      {
         toBeIncr++;
         outputBlock.Text += String.Format("{0}", toBeIncr) + "\n";
      }
      catch (Exception ex)
      {
         outputBlock.Text += String.Format("{0}", GetExceptionType(ex)) + "\n";
      }

      // Catch the exception if the decrement operator throws one.
      outputBlock.Text += String.Format("{0,-26}", "argument --");
      try
      {
         toBeDecr--;
         outputBlock.Text += String.Format("{0}", toBeDecr) + "\n";
      }
      catch (Exception ex)
      {
         outputBlock.Text += String.Format("{0}", GetExceptionType(ex)) + "\n";
      }

      outputBlock.Text += "\n";
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += String.Format("This example of the decimal increment, " +
          "decrement, unary negation, \nand unary plus operators " +
          "generates the following output. It \ndisplays the " +
          "results of the operators on several decimal values.\n") + "\n";

      // Create objects to compare with the reference.
      DecIncrDecrUnary(outputBlock, 0.000000123M);
      DecIncrDecrUnary(outputBlock, new decimal(123000000, 0, 0, false, 9));
      DecIncrDecrUnary(outputBlock, -new decimal(123000000, 0, 0, false, 9));
      DecIncrDecrUnary(outputBlock, +decimal.MaxValue);
      DecIncrDecrUnary(outputBlock, -decimal.MaxValue);
      DecIncrDecrUnary(outputBlock, +7.5000000000000000000000000001M);
   }
}

/*
This example of the decimal increment, decrement, unary negation,
and unary plus operators generates the following output. It
displays the results of the operators on several decimal values.

decimal argument:         0.000000123
argument ++               1.000000123
argument --               -0.999999877

decimal argument:         0.123000000
argument ++               1.123000000
argument --               -0.877000000

decimal argument:         -0.123000000
argument ++               0.877000000
argument --               -1.123000000

decimal argument:         79228162514264337593543950335
argument ++               OverflowException
argument --               79228162514264337593543950334

decimal argument:         -79228162514264337593543950335
argument ++               -79228162514264337593543950334
argument --               OverflowException

decimal argument:         7.5000000000000000000000000001
argument ++               8.500000000000000000000000000
argument --               6.5000000000000000000000000001
*/


Windows Phone OS

지원되는 버전: 8.0, 7.1, 7.0

Windows Phone

표시:
© 2014 Microsoft