title: How to use double.TryParse when the output is allowed to be null?
body: <p>In my application I have a textbox - <code>txtDiscount</code> where the admin can set a discount percentage for a certain user, or he may not. On the back end I want to save the data so for now I have this:</p>
  
  <pre><code>double? discount = null;
  if (!string.IsNullOrEmpty(txtDiscount.Text))
  {
    if (!double.TryParse(txtDiscount.Text, out discount)) errors.Add("Discount must be a double.");
  }
  </code></pre>
  
  <p>So I get an error for <code>invalid argument</code> and obviously it's the <code>discount</code> which can not be nullable if I'm gonna use it in <code>TryParse</code>. I saw that many people are making extensions for this type of situations but for now I don't think it's necessary. What I can think of is using another variable like so :</p>
  
  <pre><code>double? discount = null;
  private double _discount;
  if (!string.IsNullOrEmpty(txtDiscount.Text))
  {
    if (!double.TryParse(txtDiscount.Text, out _discount)) 
    {
      errors.Add("Discount must be adouble.");
    }
    else
    {
      discount = _discount;
    }
  }
  </code></pre>
  
  <p>and then use my nullable <code>discount</code> to pass the value to the database. But I actually don't like the code above, it seems to me pretty complicated for such a task but I can't think of something better. So how can I deal with this situation without using extension method?</p>