int.Parse() with leading zeros

后端 未结 8 814
粉色の甜心
粉色の甜心 2020-12-11 01:38

How do I prevent the code below from throwing a FormatException. I\'d like to be able to parse strings with a leading zero into ints. Is there a clean way to do

8条回答
  •  -上瘾入骨i
    2020-12-11 02:04

    Try

    int i = Convert.ToInt32(value);

    Edit: Hmm. As pointed out, it's just wrapping Int32.Parse. Not sure why you're getting the FormatException, regardless.

提交回复
热议问题