Input string was not in a correct format

后端 未结 8 1179
滥情空心
滥情空心 2020-11-22 02:55

I\'m new with C#, I have some basic knowledge in Java but I can\'t get this code to run properly.

It\'s just a basic calculator, but when I run the program VS2008 gi

相关标签:
8条回答
  • 2020-11-22 03:26

    You have not mentioned if your textbox have values in design time or now. When form initializes text box may not hae value if you have not put it in textbox when during form design. you can put int value in form design by setting text property in desgin and this should work.

    0 讨论(0)
  • 2020-11-22 03:27

    The error means that the string you're trying to parse an integer from doesn't actually contain a valid integer.

    It's extremely unlikely that the text boxes will contain a valid integer immediately when the form is created - which is where you're getting the integer values. It would make much more sense to update a and b in the button click events (in the same way that you are in the constructor). Also, check out the Int.TryParse method - it's much easier to use if the string might not actually contain an integer - it doesn't throw an exception so it's easier to recover from.

    0 讨论(0)
提交回复
热议问题