C#, Operator '??' cannot be applied to operands of type 'decimal' and 'decimal'
is it a decimal? or a decimal
the ?? works with a decimal? but not a decimal since a decimal can never be null.
http://msdn.microsoft.com/en-us/library/ms173224.aspx
The decimal
type cannot be null, so the null-coalesce operator makes no sense here. Just set _v1
to value
.
Those are value types and cannot be null
you can use the Nullable<decimal>
private decimal? _v1;
public decimal? V1
{
get
{
return this._v1;
}
set
{
this._v1 = value ?? 0M;
}
}
That is the Null Coalescing Operator. Since decimal can't be null, it has no use with decimal.
You can use a decimal?
which can be set to null if you need this functionality:
public decimal? v1
{
get
{
return this._v1;
}
set
{
this._v1 = value ?? 0M;
}
}