Decimal.Increment(Decimal) 操作员
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将 Decimal 操作数增加 1。
public:
static System::Decimal operator ++(System::Decimal d);
public:
static System::Decimal operator ++(System::Decimal d) = System::Numerics::IIncrementOperators<System::Decimal>::op_Increment;
public static decimal operator ++ (decimal d);
static member op_Increment : decimal -> decimal
Public Shared op_Increment (d As Decimal) As Decimal
参数
- d
- Decimal
要递增的值。
返回
d
增加 1 后的值。
实现
例外
返回值小于 Decimal.MinValue 或大于 Decimal.MaxValue。
注解
方法 Increment 定义值增量运算符 Decimal 的操作。 它启用如下代码:
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
open System
let number = 1079.8m
printfn $"Original value: {number:N}"
printfn $"Incremented value: {Decimal.op_Increment number:N}"
// The example displays the following output:
// Original value: 1,079.80
// Incremented value: 1,080.80
某些语言 ((如 Visual Basic) )缺少增量运算符,可以直接调用 Increment 方法,如以下示例所示。
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 方法,如以下示例所示。
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
open System
let number = 1079.8m
printfn $"Original value: {number:N}"
printfn $"Incremented value: {Decimal.Add(number, 1):N}"
// 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