TryParse equivalent of Convert with invariantculture

You can read about NumberStyles in the documentation. Essentially it allows you to specify what sort of text will parse.

If you want to be as flexible as possible, then NumberStyles.Any is the 'widest' option.

Convert.ToInt32 is equivalent to using int.Parse and Convert.ToDecimal is equivalent to using decimal.Parse - they delegate to these methods.

Per the documentation for int.Parse, the default is NumberStyles.Integer. And per the documentation for decimal.Parse, the default is NumberStyles.Number. If you want to be consistent with the behaviour of Convert.ToInt32 and Convert.ToDecimal, you should use these values.


The documentation for Int64.TryParse says NumberStyles.Integer is the default:

The s parameter is interpreted using the NumberStyles.Integer style. In addition to the decimal digits, only leading and trailing spaces together with a leading sign are allowed.

For Decimal.TryParse, it's NumberStyles.Number:

Parameter s is interpreted using the NumberStyles.Number style. This means that white space and thousands separators are allowed but currency symbols are not.