如何将int类型转换为字符串

编程入门 行业动态 更新时间:2024-10-26 04:28:44
本文介绍了如何将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类型转换为字符串

本文发布于:2023-11-17 06:44:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609192.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   字符串   如何将   类型   int

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!