Chris P
Chris P

Reputation: 9

can not convert type double to string using c#

Am receiving this error Cannot implicitly convert type 'double' to 'string'....i used the following code, what might be the problem? is there an easier way than mine?

QtyTextBox.Text = SimulateVal.Val(TextBox2.Text) + SimulateVal.Val(QtyTextBox.Text);

Upvotes: 1

Views: 879

Answers (3)

Patrick Allwood
Patrick Allwood

Reputation: 1832

I'm assuming that SimulateVal.Val(string) returns a double, as in a numeric type, and you want to output the sum of the two numbers as text.

QtyTextBox.Text = (SimulateVal.Val(TextBox2.Text) + SimulateVal.Val(QtyTextBox.Text)).ToString();

Upvotes: 0

cinek
cinek

Reputation: 1952

Why not:

QtyTextBox.Text = (SimulateVal.Val(TextBox2.Text) + SimulateVal.Val(QtyTextBox.Text)).ToString();

Upvotes: 0

Rezo Megrelidze
Rezo Megrelidze

Reputation: 3060

Use the Convert.ToString() method.

Upvotes: 1

Related Questions