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.'"
Asked
Active
Viewed 60 times
-3
-
This has been asked a lot before. It's a specific version of "how do I compile and execute C# code dynamically?". https://stackoverflow.com/questions/333737/evaluating-string-342-yield-int-18 – Arseniy Banayev Sep 19 '19 at 00:32
-
You want 1+ 1 to be converted to 2 ? – Chetan Sep 19 '19 at 00:33
-
1) `double` is not an integer type. 2) Such parse methods are intended for strings containing numbers. That is not what you have here. – ProgrammingLlama Sep 19 '19 at 00:33
-
Your question is [similar to this](https://stackoverflow.com/questions/174664/operators-as-strings). – ProgrammingLlama Sep 19 '19 at 00:34
1 Answers
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.

Terrence
- 131
- 5