Error at tryparse decimal conversion from textbox [closed]
Вопрос
When i read from the XML file, i read it like this and it works,
decimal checkkkk = Config.Location.test.Longitude;
textBox3.Text = checkkkk.ToString(CultureInfo.InvariantCulture);
I want to write it back to the same XML file, I'm getting a error at this point..!
decimal value;
Configs.Location.test.Longitude =
decimal.TryParse(textBox3.Text, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat, out value);
What is the mistake?
Решение
The method Decimal.TryParse returns the boolean data-type and not decimal.
Decimal.TryParse, Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format. A return value indicates whether the conversion succeeded or failed.
Try to do it this way instead:
decimal value;
if (decimal.TryParse(textBox3.Text, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat, out value))
{
rseConfigs.RseLocation.GpsCoordinates.Longitude = value;
}
Не связан с StackOverflow