Decimal.Add(Decimal, Decimal) 方法
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将两个指定的 Decimal 值相加。
public:
static System::Decimal Add(System::Decimal d1, System::Decimal d2);
public static decimal Add(decimal d1, decimal d2);
static member Add : decimal * decimal -> decimal
Public Shared Function Add (d1 As Decimal, d2 As Decimal) As Decimal
- d1
- Decimal
要相加的第一个值。
- d2
- Decimal
要相加的第二个值。
d1
与 d2
的和。
和 的总 d1
和 d2
小于 Decimal.MinValue 或大于 Decimal.MaxValue。
以下代码示例演示了 的用法 Add
:
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 = Decimal.Add(MyFortune, .01m);
}
public override string ToString() {
return MyFortune.ToString("C")+" in piggy bank";
}
protected decimal MyFortune;
}
type PiggyBank() =
let mutable myFortune = 0m
member _.AddPenny() =
myFortune <- Decimal.Add(myFortune, 0.01m)
override _.ToString() =
$"{myFortune:C} in piggy bank"
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
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |