It could be that you're using wrong comma separation symbol or even made an other error whilst specifying double value.
Anyway in such cases you must use Double.TryParse() method which is safe in terms of exception and allows specify format provider, basically culture to be used.
public static bool TryParse(
string s,
NumberStyles style,
IFormatProvider provider,
out double result
)
The TryParse method is like the Parse(String, NumberStyles,
IFormatProvider) method, except this method does not throw an
exception if the conversion fails. If the conversion succeeds, the
return value is true and the result parameter is set to the outcome of
the conversion. If the conversion fails, the return value is false and
the result parameter is set to zero.
EDIT: Answer to comment
if(!double.TryParse(Console.ReadLine(), out unitPrice))
{
// parse error
}else
{
// all is ok, unitPrice contains valid double value
}
Also you can try:
double.TryParse(Console.ReadLine(),
NumberStyle.Float,
CultureInfo.CurrentCulture,
out unitPrice))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…