По сути, вы должны увидеть, какой ввод вы передаете в функцию разбора.
Попробуйте что-то вроде следующего, чтобы увидеть немного больше о том, что происходит.
// Lets try parsing some random strings into doubles.
// Each one with varying cases.
string[] testStrings = new string[]{"$32.43", "342", "1,332", "0.93", "123,432.34", "boat"};
foreach (string ts in testStrings)
{
double newValue;
if (double.TryParse(ts, out newValue))
{
// for WPF, you can use a MessageBox or Debug.WriteLine
Console.WriteLine("We were able to successfully convert '" + ts + "' to a double! Here's what we got: " + newValue);
}
else
{
// for WPF, you can use a MessageBox or Debug.WriteLine
Console.WriteLine("We were unable to convert '" + ts + "' to a double");
}
}
Вотвывод, который вы должны увидеть:
We were unable to convert '$32.43' to a double
We were able to successfully convert '342' to a double! Here's what we got: 342
We were able to successfully convert '1,332' to a double! Here's what we got: 1332
We were able to successfully convert '0.93' to a double! Here's what we got: 0.93
We were able to successfully convert '123,432.34' to a double! Here's what we got: 123432.34
We were unable to convert 'boat' to a double