In a lot of places in my code I have this:
try
{
price = double.Parse(sPrice.Replace(",", "."), CultureInfo.InvariantCulture);
}
catch
{
price = 0;
}
I read somewhere that if the exception is thrown in the try block, it takes a lot of time being caught.
So, I'd like to use tryparse instead of parse, like this:
if (!double.TryParse(sPrice, out price))
{
price = 0;
}
Is this a good practice? Will it take less time?