Rectangle 27 0

asp.net c int.Parse or Convert.toInt?


Parse is specifically to parse strings and gives you more control over what format the string may be. Convert.ToInt will handle almost any type that can be converted in the first place. What is more error prone depends on your input and the variations you expect. int.TryParse is robust in that it won't throw an exception, the pitfall is that it is easy to hide the parsing error. This choice depends on what you want to do? Do you want to provide feedback, have detailed parsing error info, use alternative / default values?

Note