[英]Decrement or Increment decimal value
in my c# solution i have : 在我的C#解决方案中,我有:
private void DecrementProduct()
{
decimal? difference = this.Difference;
this.Difference = new decimal?((difference.HasValue ? difference.GetValueOrDefault() : new decimal(0))--);
}
visual studio return error : Error 107 :The operand of an increment or decrement operator must be a variable, property or indexer. visual studio返回错误:错误107:递增或递减运算符的操作数必须是变量,属性或索引器。
where is problem? 问题在哪里?
The error is pretty self explanatory. 该错误很容易解释。 You are using the decrement operator on a value, it needs to be a variable property or indexer.
您正在对值使用减量运算符,它必须是变量属性或索引器。
It's akin to doing: 这类似于:
var foo = 10--;
You should probably just make it this: 您可能应该做到这一点:
this.Difference = difference - 1 ?? -1;
private void DecrementProduct()
{
if(this.Difference.HasValue)
this.Difference = this.Difference.Value - 1M;
else
this.Difference = -1M;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.