It's allowing thousands, because the default NumberStyles
value used by Decimal.Parse
(NumberStyles.Number
) includes NumberStyles.AllowThousands
.
If you want to disallow the thousands separators, you can just remove that flag, like this:
Decimal.Parse("1,2,3,4", NumberStyles.Number ^ NumberStyles.AllowThousands)
(the above code will throw an InvalidFormatException
, which is what you want, right?)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…