当我转换的Int32格式异常 [英] Format exception when I am converting to Int32

查看:110
本文介绍了当我转换的Int32格式异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我试图将一个值转换的Int32,我得到一个错误格式异常,这意味着该值不正确的格式。我想我转换以正确的格式值虽然。

While i am trying to convert a value to Int32, I get an error format exception, meaning the value is not in the proper format. I think I am converting a value in right format though.

推荐答案

您将获得 FormatException 在这种情况下一个:

You will get FormatException in cases such next:

Convert.ToInt32("foo");
Convert.ToInt32(5.5);

由于

FormatException

FormatException

值不包括可选符号后跟(0-9)的数字序列。

value does not consist of an optional sign followed by a sequence of digits (0 through 9).

MSDN

这篇关于当我转换的Int32格式异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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