i’m following the how do i series for lightswitch, and converting the code as i go from VB to C#
i’m getting stuck on a computed property that is multiplying two fields and returning the result
the error is "Cannot implicitly convert type ‘decimal?’ to ‘decimal’. An explicit conversion exists (are you missing a cast?)".
i’m not sure why i would need a cast since they are both of the same type
thanks,
Jason
VB Code
Private Sub LineItemTotal_Compute(ByRef result As Decimal)
result = Me.Quantity * Me.Price
End Sub
C# Code
private void LineItemTotal_Compute(ref decimal result)
{
result = this.Quantity * this.Price;
}

Your properties are
decimal?s (nullable).As the error states, you cannot implicitly convert a nullable decimal to an ordinary (non-nullable) decimal.
Instead, you can write
?? 0to coalesce to0if it’s null.However, you should consider making the other columns non-nullable as well to avoid the issue altogether.