Jump to content
  • Advertisement
Sign in to follow this  

[C#] Problem performing math with nullable types

This topic is 3975 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!