为什么我收到此错误输入字符串格式不正确。 [英] why i get this error Input string was not in a correct format.

查看:178
本文介绍了为什么我收到此错误输入字符串格式不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int a = 0;

a = Convert.ToInt32(Label12.Text.ToString()); //错误



Label12 .text中有一些值..



错误:



输入字符串的格式不正确...



我该怎么做才能解决这个错误???

int a = 0;
a=Convert.ToInt32(Label12.Text.ToString());//error

Label12.text has some values in it..

error:

Input String was not in correct format...

What should i do to solve this error???

推荐答案

因为正文标签的格式不是有效的,不能解析为整数。更重要的是,整个事情毫无意义。 Label是一个静态控件(文本不会被用户修改),所以为什么解析它呢?完全没有意义。



-SA
Because the text of the label is not in valid format, cannot be parsed as integer. More importantly, the whole thing makes no sense. Label is a static control (text is not modified by the user), so why parsing it, ever? Makes no sense at all.

—SA


你不能直接将字符串转换为整数。

使用 Interger.TryParse 以避免转换过程中的错误。
You cannot directly convert a string to an integer.
Use Interger.TryParse to avoid errors during conversion.


这篇关于为什么我收到此错误输入字符串格式不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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