问题
protected void btnAdd_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(ltAvailable.Text);
int b = Convert.ToInt32(txtInput.Text);
ltTotal.Text = a + b;
How can i add values in a literal and a textbox? Thanks
回答1:
Here:
ltTotal.Text = (a + b).ToString();
回答2:
protected void btnAdd_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(ltAvailable.Text);
int b = Convert.ToInt32(txtInput.Text);
ltTotal.Text = (a + b).ToString();
You just need to call .ToString()
on your calculation result
This would also work
ltTotal.Text = Convert.ToString(a + b)
来源:https://stackoverflow.com/questions/33401578/cs0029-cannot-implicitly-convert-type-int-to-string