Why decimal.Parse(10 10) is valid?
I need to get exception in such case.
Please advise me something.
decimal c;
try
{
c = decimal.Parse("10 10");
Console.Write(c);
Console.ReadLine();
}
catch (Exception)
{
throw;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This throws an exception when I run it – which leads me to suspect that it’s culture-sensitive.
My guess is that you’re in a culture which uses space as a “thousands” separator. For example, if I try to parse “10,10” that works because comma is the thousands separator in my default culture.
To prevent this, use
… or some other appropriate combination of
NumberStyleswhich excludesAllowThousands.