Decimal.Decrement(Decimal) 操作员

定义

Decimal 操作数减 1。Decrements the Decimal operand by one.

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

参数

d
Decimal

要递减的值。The value to decrement.

返回

d 减 1 所得的值。The value of d decremented by 1.

异常

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

注解

Decrement 方法定义 Decimal 值的减量运算符的运算。The Decrement method defines the operation of the decrement 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("Decremented value: {0:N}", --number); 
   }
}
// The example displays the following output:
//       Original value:    1,079.80
//       Decremented value: 1,078.80

缺少增量运算符的某些语言(如 Visual Basic)可以直接调用 Decrement 方法,如下面的示例所示。Some languages (such as Visual Basic) that lack an increment operator can call the Decrement 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("Decremented value: {0:N}", Decimal.op_Decrement(number))
   End Sub
End Module
' The example displays the following output:
'       Original value:    1,079.80
'       Decremented value: 1,078.80

如果你的语言不支持自定义运算符,请改为调用 Subtract 方法,如下面的示例所示。If your language does not support custom operators, call the Subtract 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("Decremented value: {0:N}", Decimal.Subtract(number, 1)); 
   }
}
// The example displays the following output:
//       Original value:    1,079.80
//       Decremented value: 1,078.80
Module Example
   Public Sub Main()
      Dim number As Decimal = 1079.8d
      Console.WriteLine("Original value:    {0:N}", number)
      Console.WriteLine("Decremented value: {0:N}", Decimal.Subtract(number, 1))
   End Sub
End Module
' The example displays the following output:
'       Original value:    1,079.80
'       Decremented value: 1,078.80

适用于

另请参阅