日期:2014-05-17  浏览次数:20423 次

为啥类型转换总出错阿

int temp2 = Convert.ToInt32 (gv.Rows[i].Cells[12+reccount].Text);
其中gv.Rows[i].Cells[12+reccount].text是数字,用convert或者parse 转换的时候,总是出错。

System.FormatException: Input string was not in a correct format.



------解决方案--------------------
几种常用的转换方式。。拿int型举例。。

Convert.ToInt32(); //将object类型转换为int型

int.Parse(); //将string型转换为int型

(int)... //一般的类型转换,比如将浮点型数据转成整型。。