Decimal.Increment(Decimal) Decimal.Increment(Decimal) Decimal.Increment(Decimal) Decimal.Increment(Decimal) Operator

定義

Decimal 運算元加 1。Increments the Decimal operand by 1.

public:
 static System::Decimal operator ++(System::Decimal d);
public static decimal operator ++ (decimal d);
static member op_Increment : decimal -> decimal
Public Shared op_Increment (d As Decimal) As Decimal

參數

d
Decimal Decimal Decimal Decimal

要遞增的值。The value to increment.

傳回

加 1 的 d 值。The value of d incremented by 1.

例外狀況

傳回值小於 MinValue 或大於 MaxValueThe return value is less than MinValue or greater than MaxValue.

備註

方法會定義Decimal值之遞增運算子的運算。 IncrementThe Increment method defines the operation of the increment operator for Decimal values. 它會啟用如下所示的程式碼:It enables code such as the following:

using System;

public class Example
{
   public static void Main()
   {
      Decimal number = 1079.8m;
      Console.WriteLine("Original value:    {0:N}", number);
      Console.WriteLine("Incremented value: {0:N}", ++number); 
   }
}
// The example displays the following output:
//       Original value:    1,079.80
//       Incremented value: 1,080.80

缺少遞增運算子的某些語言(例如 Visual Basic)可以直接呼叫Increment方法,如下列範例所示。Some languages (such as Visual Basic) that lack an increment operator can call the Increment method directly, as the following example shows.

Module Example
   Public Sub Main()
      Dim number As Decimal = 1079.8d
      Console.WriteLine("Original value:    {0:N}", number)
      Console.WriteLine("Incremented value: {0:N}", Decimal.op_Increment(number))
   End Sub
End Module
' The example displays the following output:
'       Original value:    1,079.80
'       Incremented value: 1,080.80

如果您的語言不支援自訂運算子,請Add改為呼叫方法,如下列範例所示。If your language does not support custom operators, call the Add method instead, as the following example shows.

using System;

public class Example
{
   public static void Main()
   {
      Decimal number = 1079.8m;
      Console.WriteLine("Original value:    {0:N}", number);
      Console.WriteLine("Incremented value: {0:N}", Decimal.Add(number, 1)); 
   }
}
// The example displays the following output:
//       Original value:    1,079.80
//       Incremented value: 1,080.80
Module Example
   Public Sub Main()
      Dim number As Decimal = 1079.8d
      Console.WriteLine("Original value:    {0:N}", number)
      Console.WriteLine("Incremented value: {0:N}", Decimal.Add(number, 1))
   End Sub
End Module
' The example displays the following output:
'       Original value:    1,079.80
'       Incremented value: 1,080.80

適用於

另請參閱