Solve the error of the "Input Character Format in Entrance" in C#
When running the basic C#calculator program, you may encounter an error message "Incorrect input string format". This error shows that you try to convert to an integer string that does not meet the correct integer format.
The problem is that you try to input the text box into an integer in the constructor of the window. However, when the window is created, these text boxes are unlikely to include an effective integer at the beginning.
The better method is to update the 'a' and 'B' variable in the button to click on the event, similar to the way you initialize them in the constructor:
This ensures that when you click the button, the variable will use the current value of the user input to update. In addition, do not use , but consider using
<code class="language-csharp">private void button1_Click(object sender, EventArgs e) { a = Int32.Parse(textBox1.Text); b = Int32.Parse(textBox2.Text); add(); result(); }</code>
Int32.Parse
The above is the detailed content of How to Fix the 'Input String Was Not in a Correct Format' Error in C#?. For more information, please follow other related articles on the PHP Chinese website!