c*******s 发帖数: 179 | 1 首先,感谢你的贴子.
我实验了你提供的方法,但是系统给出了下面的错误信息:
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll
Additional information: Input string was not in a correct format.
我是这样转化得到的字符串数组的.
char x_char [20]; %已经得到
string x_str=x_char.toString();
%虽然成功,但是检查内存,发现x_str是一个System.char[],并不是相象的string;
double xx=Convert.TODouble(x_str);%系统报错在这里 | j**o 发帖数: 4 | 2 It's the compiler that creates the char[] class which derives from
System.Array. It's ToString() method is inherited from Object, so it returns
the full class name, not the concatenation of chars you might have expected.
Here's what works:
char[] x_char = "12.34".ToCharArray();
string str = new string(x_char);
double xx;
try
{
xx = Convert.ToDouble(str);
}
catch (FormatException ex)
{
.....
}
Actually you don't deal with char[] that much anymore, you should be using
string most of the time.
【在 c*******s 的大作中提到】 : 首先,感谢你的贴子. : 我实验了你提供的方法,但是系统给出了下面的错误信息: : An unhandled exception of type 'System.FormatException' occurred in : mscorlib.dll : Additional information: Input string was not in a correct format. : 我是这样转化得到的字符串数组的. : char x_char [20]; %已经得到 : string x_str=x_char.toString(); : %虽然成功,但是检查内存,发现x_str是一个System.char[],并不是相象的string; : double xx=Convert.TODouble(x_str);%系统报错在这里
|
|