尝试将String转换为Double时出现System.FormatException

use*_*470 2 c# windows-phone-7

当我在WP7 C#上尝试将String转换为Double时,我遇到了这个错误.

tokenvalue = Convert.ToDouble(saParsed[i].Replace(".", ","));
Run Code Online (Sandbox Code Playgroud)

我在WP7中遇到此错误.System.FormatException发生类型的第一次机会异常mscorlib.dll

有没有办法避免它或只是它是模拟器的错?

Mar*_*rco 7

首先,您可以尝试使用此:

double tokenvalue = Convert.ToDouble(saParsed[i], CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)

无论如何你最好检查一下是否正常:

double tokenvalue;
if (Double.TryParse(saParsed[i], out tokenvalue) 
{ 
    // Do what you please here
}
Run Code Online (Sandbox Code Playgroud)