Checking if a variable is of data type double

后端 未结 10 1231
無奈伤痛
無奈伤痛 2021-02-08 02:19

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);
}
c         


        
10条回答
  •  一个人的身影
    2021-02-08 02:45

    Couldn't you just use:

    double.Parse(txtPrice.Text);
    

    ?

    With this you will a FormatException saying "Input string was not in a correct format." if the string value isn't a double, which looks to be roughly what you were doing manually anyway.

提交回复
热议问题