title: How do I use a null value in a double in VB.Net 2010?
body: <p>Straightforward question: I have a few variables that are doubles. I would like to be able to store a "null" state in them, i.e. I need to be able to represent that the variable doesn't contain valid data. I'd really rather not associate a boolean "is valid" variable with every single double, that would be ugly and likely unnecessary.</p>
  
  <p>First, I found out that one has to declare the variable differently to allow the concept of 'IsNothing' to be checked, so I do this:</p>
  
  <pre><code>dim someDouble as Double?
  </code></pre>
  
  <p>(Note the question mark). If I don't declare it like that, the error check gives me a "IsNot requires operands that have reference types" message.</p>
  
  <p>Once declared, setting the variable to...</p>
  
  <pre><code>someDouble = Nothing
  </code></pre>
  
  <p>...seems to set it to <em>zero</em>, because it never runs the code in my if/else statement that checks whether <code>someDouble IsNot Nothing</code>... which is bad because the variable can legitimately store a 0 as a valid piece of data.</p>
  
  <p>What am I missing here? Thanks!</p>
  
  <p>EDIT: I left out that I was using properties in a class to <code>Get</code> and <code>Set</code> these values. It turns out I was doing things right except I left my <code>Property</code>'s type as a <code>Double</code> instead of a <code>Double?</code> so it was casting back to zero instead of the <code>Nothing</code> value. Useful information still in the answers below, though!</p>