2010-08-03 31 views
2
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类型的?)值?

回答

3

直接指定它。

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

是不是有太多'}'现在在编辑版本? – JLWarlow 2010-08-03 14:30:56

+0

或者一个太少''''。 :-) 更正。 – tdammers 2010-08-03 16:17:00