Usefull helper

The default parsing method for C# using current culture, which sucks really badly. ( I wrote about it on SO)

Here a lil helper that I use

public static class Helper
{
	public static bool TryParseDouble(this TextBox textbox, out double value)
	{
		if (double.TryParse(textbox.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
		{
			textbox.Foreground = Brushes.Black;
			return true;
		}
		else
		{
			textbox.Foreground = Brushes.Red;
			return false;
		}
	}

	public static bool TryParseDouble(this string text, out double value)
	{
		return double.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out value);
	}
}
Written on December 7, 2011