C#Form Application int to string error

Ker*_*y G 0 c# forms if-statement

我真的被困在这一个 - 我正在尝试创建一个if语句并在文本框中显示分配给变量的值.我一直遇到一个"无法将imp int转换为字符串"的构建错误.谢谢.

        int n1;
        int userInput = int.Parse(textBox1.Text);
        if (userInput == 4)
        {
            n1 = 60;

        }
        else if (userInput ==3)
       { 
             n1=40
       }


        {
        textBox2.Text = (n1); //"Cannot implicity convert int to string" 
        }
Run Code Online (Sandbox Code Playgroud)

pra*_*nth 5

你宣布n1int.该Text属性textBox2属于类型string.因此,您首先必须转换n1string之前可以将其分配给Text.

textBox2.Text = n1.ToString();
Run Code Online (Sandbox Code Playgroud)