0

how to show the numbers in textbox in c# . it is show to me 11 does not show 2 why ??

public partial class Form1 : Form { public Form1() { InitializeComponent(); } double o1; string one; private void textBox1_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { textBox1.Text += "1"; one += "1"; } private void button2_Click(object sender, EventArgs e) { double o1 = Convert.ToDouble(textBox1.Text); textBox1.Text += "+"; } private void button3_Click(object sender, EventArgs e) { string o2 = Convert.ToString(textBox1.Text); textBox1.Clear(); String[] pr = new String[] { o2 }; if (pr[0].Contains("+")) { pr[0] = pr[0].Replace("+", ""); double d = Convert.ToInt16(pr[0]); double v = d + o1; string x =Convert.ToString(v); textBox1.Text += x; }

27th May 2017, 10:38 PM
ALAMOUDI, WAEL MAKKI S
ALAMOUDI, WAEL MAKKI S - avatar
2 odpowiedzi
+ 2
Because it treats it as a string. 1 + 1 = 11. Hello + world = helloworld
27th May 2017, 11:45 PM
aklex
aklex - avatar
+ 1
i convert it to double but no work
27th May 2017, 11:53 PM
ALAMOUDI, WAEL MAKKI S
ALAMOUDI, WAEL MAKKI S - avatar