-3

I have i = double.Parse(TextBox.Text); but when I enter the + symbol, this error appear "System.FormatException: 'Input string was not in a correct format.'"

1 Answers1

1

If I understand correctly, you have a much larger issue than you think.

Your textbox has a string. In this case, "1+1" is the value in your textbox. However, that cannot be parsed to an integer value because it contains the plus sign. The plus sign is a character, it is not an integer (0,1,2,3,4..). So, what you get is a data type conversion conflict.

From what I gather, you'd like to evaluate that expression and then store the value into into the i variable. In this case, you would like i to equal 2.

You will need to evaluate the string and convert it into a formula then use the result to store in the variable.

Here's a link to an example of a conversion formula.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/7f62b87d-a35c-4074-a0f0-84a9dd7ff0a5/convert-string-to-formula?forum=csharpgeneral

Terrence
  • 131
  • 5