+ 1

About TextBox in C#

Hello guys.. My question is what's difference of : int x = Convert.ToInt32(textBox.Text); and textBox1.Text = Convert.ToString(int x); In this case, I using that statement for sum two value in textBox.... Please help me... Thanks a lot Regards

5th Apr 2019, 12:00 PM
Debby Ummul Hidayah
Debby Ummul Hidayah - avatar
5 Answers
+ 2
You want to sum two values, so you should have two text boxes, am I right?
5th Apr 2019, 1:50 PM
Gordon
Gordon - avatar
+ 2
label1.Text = Convert.ToInt32(textbox1.Text) + Convert.ToInt32(textbox2.Text); You need to convert to Int for arithmetic addition.
5th Apr 2019, 2:43 PM
Gordon
Gordon - avatar
+ 2
You are welcome Basically you need four Controls in your Graphical Interface : two input box, one display box (Label named label1) and a button. Put the above in a click function of button. The conversion is because input are string. For output, string and numbers both ok. For convert int, you can only process integers. Convert to float if you want to extend the coverage to decimal numbers. You may want to add two lines to empty the input text boxes after calculation.
6th Apr 2019, 2:33 AM
Gordon
Gordon - avatar
0
Yes, you are right....
5th Apr 2019, 2:08 PM
Debby Ummul Hidayah
Debby Ummul Hidayah - avatar
0
Nice answer.... Ok sir...I will try it
6th Apr 2019, 2:19 AM
Debby Ummul Hidayah
Debby Ummul Hidayah - avatar