Input string was not in a correct format in double.Parse

前端 未结 5 1444
遥遥无期
遥遥无期 2020-12-07 02:50

I am new to C#. I\'m trying to make a calculator, but the following error occurred:

Input string was not in a correct format.

T

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 03:53

    Also remember that the Parse method is relying on the culture of your operating system to perform the conversion, so try to change your code to

    num2 = double.Parse(textBox1.Text, CultureInfo.InvariantCulture);
    

    You might also consider to use the

    double.TryParse
    

    method for better exception handling.

提交回复
热议问题