C# 用C将字符串简单地添加到int#
我有PHP方面的知识,我想学习C语言,但我甚至不做简单的加法 我想得到一个组合框的值,将这个值转换为int,并能够添加另一个值 尽管完成了转换,但我有一个错误:无法将类型“int”转换为“string” 我的代码: private void btnValidate_click(object sender, RoutedEventArgs e) { int number = Test(); } int Test() { string day = DayBirth.Text; int number; bool isNumeric = int.TryParse(day, out number); if (isNumeric == false) { Resultat1.Text = "This is not a number"; } else { Resultat1.Text = number + 10; } return number; } 私有无效btnValidate_单击(对象发送者,路由目标e) { int number=Test(); } int测试() { 字符串day=daybearth.Text; 整数; bool isNumeric=int.TryParse(日期,输出编号); 如果(isNumeric==false) { Resultat1.Text=“这不是一个数字”; } 其他的 { 结果1.文本=数字+10; } 返回号码; }C# 用C将字符串简单地添加到int#,c#,string,int,addition,C#,String,Int,Addition,我有PHP方面的知识,我想学习C语言,但我甚至不做简单的加法 我想得到一个组合框的值,将这个值转换为int,并能够添加另一个值 尽管完成了转换,但我有一个错误:无法将类型“int”转换为“string” 我的代码: private void btnValidate_click(object sender, RoutedEventArgs e) { int number = Test(); } int Test() { string
谢谢您需要做的是在添加后将数字转换为字符串
Resultat1.Text = (number + 10).ToString;
您需要做的是在加法后将数字转换为字符串
Resultat1.Text = (number + 10).ToString;
问题是Resultat1.Text需要的是字符串,而不是int。您可以这样做
Resultat1.Text = (number+10).ToString();
它应该可以工作。问题是Resultat1.Text需要字符串,而不是int。您可以这样做
Resultat1.Text = (number+10).ToString();
它应该可以工作。
Text
属性接受字符串值而不是整数,因此在加法后必须将其转换为字符串
Resultat1.Text = (number + 10).ToString();
Text
property接受字符串值而不是整数,因此添加后必须将其转换为字符串
Resultat1.Text = (number + 10).ToString();
谢谢你的帮助没关系谢谢你的帮助没关系