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

标签 c#-4.0 nullable

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/

相关文章:

c# - 运行数据库查询而不是等待结果

c# - C#长数据类型拆箱问题

c# - 如何在 WPF 的 tabItem 中控制焦点

c# - 如何将可为空的 DateTime 转换为 UTC DateTime

c# - 一个单一的通用解决方案?

spring-webflux - WebFlux 和 null 值

linq - ERROR 静态方法需要空实例,非静态方法需要非空实例

c# - RegLoadAppKey 在 32 位操作系统上运行良好,在 64 位操作系统上失败,即使两个进程都是 32 位的

c# - 可空引用类型 : How to specify "T?" type without constraining to class or struct

c# - C# 中的可空变量是否可以从某个时间点为编译器标记为非空?