如何将int类型转换为字符串 [英] how to convert type int to string

查看:101
本文介绍了如何将int类型转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是shailendra singh.任何人都可以帮助我.我为此代码而苦.

lblEtotal=(Convert.ToString((lblEW.Text) + (lblEfa1.Text) + (lblEfa11.Text)));

我想将此代码转换为字符串,但标签无法转换.如何将数据,lblEtotal,lblEw,lblEfa1,lblEfa11转换为标签.请帮助我.




感谢您的进步.

Hi

I am shailendra singh .any one help me .I am suffering for this code .

lblEtotal=(Convert.ToString((lblEW.Text) + (lblEfa1.Text) + (lblEfa11.Text)));

I want to covert this code int to string but label cannot covert .how can covert data ,lblEtotal,lblEw,lblEfa1,lblEfa11 are label .please help me .




Thanks for advance.

推荐答案

将每个文本字段转换为数字,然后将它们加在一起:
Convert each Text feild to a number, and then add them together:
lblETotal.Text = (int.Parse(lblEW.Text) + int.Parse(lblEfa1.Text) + int.Parse (lblEfa11.Text)).ToString();



[edit]忘记了标签输出中的.Text:O-OriginalGriff [/edit]



[edit]Forgot the .Text on the label output :O - OriginalGriff[/edit]


首先请参见
如果
lblEtotal是一个标签,然后分配为

lblEtotal.Text =您要分配的值.

lblEW.Text
lblEfa1.Text
lblEfa11.Text
将是字符串本身.如果要将它们转换为整数,并将它们的总和分配给lblEtotal.
然后

First see
if
lblEtotal is a label then assign as

lblEtotal.Text=value that you want to assign.

lblEW.Text
lblEfa1.Text
lblEfa11.Text
will be string itself.If you want to convert these into integer and sum of these assign to lblEtotal.
then

lblEtotal.Text=(int.Parse(lblEW.Text) + int.Parse(lblEfa1.Text) + int.Parse(lblEfa11.Text)).ToString();


这是另一种解决方案:
Here is another solution :
int n1, n2, n3;
if (int.TryParse(lblEW.Text, out n1) && int.TryParse(lblEfa1.Text, out n2)) && int.TryParse(lblEfa11.Text, out n3))
               lblEtotal.Text= (n1+n2+n3).ToString;



希望对您有所帮助.



Hope it helps.


这篇关于如何将int类型转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆