C#整数字符串

编程入门 行业动态 更新时间:2024-10-28 10:22:06
本文介绍了C#整数字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何将标签文本转换为数字,该文本只会是数字,这是我的代码.

How do i convert a labels text into a number,, this text will only be numbers, this is my code.

private void ShortCut_Load(object sender, EventArgs e) { string variable = form2size.Text; int value; int.TryParse(variable, out value); this.Size = new Size(this.Size.Width + value, 130); }

推荐答案

是的,它看起来正确.那是什么问题呢? Int32.TryParse [ ^ ]转换成功后将返回true Yes it look correct. And what is the problem then ? Int32.TryParse[^] will return true when convert successed

使用异常处理处理错误.... Use Exception Handling to handle the error.... private void ShortCut_Load(object sender, EventArgs e) { int value = 0; try { value = Convert.ToInt32(form2size.Text); } catch {} this.Size = new Size(this.Size.Width + value, 130); }

String Converted= int.Parse(label1.Text);

将为您提供帮助.

Will help you.

更多推荐

C#整数字符串

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

发布评论

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

>www.elefans.com

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