Difference b/w int32 and intparse??
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mukesh KumarRank #119 · 18.2K reputationPosted Nov 26, 2015, 10:11 PM EST
If you've got a string, and you expect it to always be an integer (say, if some web service is handing you an integer in string format), you'd use
Int32.Parse().If you're collecting input from a user, you'd generally use
Int32.TryParse(), since it allows you more fine-grained control over the situation when the user enters in invalid input.Convert.ToInt32()takes an object as its argument, and I believe it invokesInt32.TryParse()when it finds that the object taken as the argument is a string.Convert.ToInt32()also does not throwArgumentNullExceptionwhen it's argument is null the wayInt32.Parse()does. That also means thatConvert.ToInt32()is probably a wee bit slower thanInt32.Parse(), though in practice, unless you're doing a very large number of iterations in a loop, you'll never notice it.Aishwarya D106 reputationPosted Nov 26, 2015, 10:14 PM EST