Any performance difference between int.Parse() and Convert.Toint()?

前端 未结 6 1796
孤独总比滥情好
孤独总比滥情好 2020-12-15 04:27

Is there any significant advantages for converting a string to an integer value between int.Parse() and Convert.ToInt32() ?

string stringInt = \"01234\";

i         


        
6条回答
  •  被撕碎了的回忆
    2020-12-15 05:00

    See this discussion for details.

    Convert.ToInt32 won't throw as often (if stringInt == null, it returns 0 instead of throwing an exception), but has a slight bit more overhead since it's doing a few extra checks, then calling int.Parse internally.

提交回复
热议问题