gpt4 book ai didi

c#-4.0 - 如何修改可为空类型的值?

转载 作者:行者123 更新时间:2023-12-04 06:48:55 24 4
gpt4 key购买 nike

public partial class L2SEntity {
public void Scale(double d) {
if (this.Amount.HasValue)
this.Amount.Value *= d;
}
}

导致以下错误:
Error   2   Property or indexer 'System.Nullable<double>.Value' cannot be assigned to -- it is read only

如何更改金额的( double 类型?)值?

最佳答案

直接赋值就行了。

public partial class L2SEntity {
public void Scale(double d) {
if (this.Amount.HasValue) {
this.Amount *= d;
}
}
}

关于c#-4.0 - 如何修改可为空类型的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3397350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com