How to Sum Nullable property values?

Hobbyist_programmer 621 Reputation points
2021-03-30T11:58:45.7+00:00

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

Developer technologies | VB
{count} votes

Answer accepted by question author
  1. Viorel 126.3K Reputation points
    2021-03-30T12:46:59.717+00:00

    Try one of solutions:

    Return C1.GetValueOrDefault + C2.GetValueOrDefault + C3.GetValueOrDefault
    
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.