title: Input string was not in a correct format. Converting String to double
body: <p>I'm quite a beginner in C# , empty string to double conversion can be carried out under the <code>button1_click</code> event ..but doing it under <code>Public Form1()</code>  it gives me this error </p>
  
  <blockquote>
    <p>Input string was not in a correct
    format.</p>
  </blockquote>
  
  <p>Here`s the code..(the form1.cs and the Guy.cs class)</p>
  
  <pre><code> using System;
   using System.Collections.Generic;
   using System.ComponentModel;
   using System.Data;
   using System.Drawing;
   using System.Linq;
   using System.Text;
   using System.Windows.Forms;
  
   namespace WindowsFormsApplication1
   {
       public partial class Form1 : Form
       {
          public Form1()
          {
              InitializeComponent();
  
              guy1 = new Guy() ;
              guy1.guyname = textBox1.Text;                
              guy1.guycash = double.Parse(textBox2.Text);
          }                 
  
      }
  
      Guy guy1 ;
  
      private void button1_Click(object sender, EventArgs e)
      {
  
          label5.Text = guy1.TakeCash(double.Parse(textBox3.Text)).ToString();
  
      }
   }
  
  
  }
  </code></pre>
  
  <p>The Guy.cs Code :</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication1
  {
      class Guy
      {
          private string name;
          private double cash;
  
          public string guyname
          {
              get { return name; }
              set { name = value; }
          }
  
          public double guycash
          {
              get { return cash ; }
              set { cash = value; }
          }
  
  
  
          public double TakeCash(double amount)
          {
              if (cash &gt; amount)
              {
                  cash -= amount;
                  return cash;
              }
              else
              {
                  MessageBox.Show("Not enough Cash.");
                  return 0;
              }
          }
  
  
      }
  }
  </code></pre>
  
  <p>the error is caused by the <code>guy1.guycash = double.Parse(textBox2.Text);</code> line , when i try <code>double.TryParse(textbox2.Text, out x)</code> in If() before it, it returns false .</p>
  
  <p>how to solve this please ?
  thanks in advance .</p>