question

Hobbyistprogrammer-7674 avatar image
0 Votes"
Hobbyistprogrammer-7674 asked Hobbyistprogrammer-7674 commented

How to Sum Nullable property values?

Hallo,

I have class object and it has some Nullable properties like ( Public property C1 as integer?, C2 as integer? ....etc) and i have a read only property like below but it does not sum when any of the property is null. What is the correct way to Sum? Thanks

Public read only property Total as integer?
Get
Return C1 + C2 + C3
End get
End property

dotnet-visual-basic
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

See nullable-value-types for why this happens. Viorel's answer is correct.


1 Vote 1 ·

1 Answer

Viorel-1 avatar image
2 Votes"
Viorel-1 answered Hobbyistprogrammer-7674 commented

Try one of solutions:

 Return C1.GetValueOrDefault + C2.GetValueOrDefault + C3.GetValueOrDefault

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.