I need to check if a variable I have is of the data type double. This is what I tried:
try
{
double price = Convert.ToDouble(txtPrice.Text);
}
catch (FormatException)
{
MessageBox.Show("Product price is not a valid price", "Product price error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
I thought this would work, but obviously, I failed to realize if txtPrice.Text had anything other than a number in it, the Convert class will just parse it out.
How can I realiably check if a variable is a double?
Use this: