At this moment i am trying to get a double value from textbox like this:
String.IsNullOrEmpty(textBox1.Text) ? 0.0 : Double.Parse(textBox1.Text)
If Double.TryParse
is unable to parse the string, it returns false and sets the out parameter to 0.
double d;
if(double.TryParse(textBox1.Text, out d)
{
// valid number
}
else
{
// not a valid number and d = 0;
}
Or
double d;
double.TryParse(textBox1.Text, out d)
// do something with d.
Also note that you can use the out parameter in additional logic within the same if statement:
double d;
if(double.TryParse(textBox1.Text, out d) && d > 500 && d < 1000)
{
// valid number and the number is between 501 and 9999
}