Re: Saving srting problem
Are you forgetting to set value X when they click the button? Something like:
Code:
private void button1_Click(object sender, EventArgs e)
{
Int32.TryParse(txtBox.Text, out X);
}
What you have should work.
Re: Saving srting problem
If you're going to use TryParse, you should always check the result:L
Code:
if( !Int32.TryParse(txtBox.Text, out X) )
MessageBox.Show("Hey! That's not valid!"); //Some error message
Otherwise just use
Code:
X = Int32.Parse(txtBox.Text);
Which will throw an exception if you can't parse the string. Obviously, in code dealing with user-input the TryParse-and-check method is better than the exception handling method.