Csharp/C#教程:无法将int类型转换为System.Windows.Forms.Label分享


无法将int类型转换为System.Windows.Forms.Label

我正在制作一个随机数生成器,但我无法让它工作。 它说不能将int类型转换为System.Windows.Forms.Label

private void button1_Click(object sender, EventArgs e) { Random r1 = new Random(); string a = Text1.Text int b = int.Parse(a); b++; abc.Text = r1.Next(b).ToString(); } } } 

改变了 上面的代码现在是正确的。 谢谢您的帮助!

我想你只需要使用abc标签的Text属性;

 abc.Text = r1.Next(b).ToString(); 

您将值分配给标签而不是标签的文本。 这条线

 abc = r1.Next(b); 

应该

 abc.Text = r1.Next(b).ToString(); 

该错误试图告诉您它无法将int对象转换为Label对象

当然你不会给标签分配整数..

您必须设置标签的text属性

上述就是C#学习教程:无法将int类型转换为System.Windows.Forms.Label分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 abc.Text = r1.Next(b).ToString(); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/942350.html

(0)
上一篇 2021年11月13日
下一篇 2021年11月13日

精彩推荐