CS0029: Cannot implicitly convert type 'int' to 'string' [duplicate]

被刻印的时光 ゝ 提交于 2019-12-13 09:48:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!