Sign in to follow this  

[C#] Problem performing math with nullable types

This topic is 3782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is my problem, in general terms: 1. First I perform a database query that returns values that at some point are guaranteed to be "null." I have no control over this. 2. Second, I pass the returned values as paramaters into a method as nullable types. 3. Third, Inside the method I perform math on these values, then display them. MY PROBLEM: An exception is thrown each time the method tries to perform math on a null value. MY WORKAROUND, I created a bunch of if statements at the beginning of the method that tests each parameter to see if it's null. If it is, it sets that parameter value to "0." This makes me cringe, however, as it seems like a very inelegant solution to the problem. Does anyone know a better way to solve this problem? I'd appreciate any direction...

Share this post


Link to post
Share on other sites

This topic is 3782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this