What is the difference between Parse() and TryParse()?
int number = int.Parse(textBoxNumber.Text); // The Try-Parse Method int.TryParse(textBoxNumber.Text, out number);
Is there some form of error-checking like a Try-Catch Block?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Parsethrows an exception if it cannot parse the value, whereasTryParsereturns aboolindicating whether it succeeded.TryParsedoes not justtry/catchinternally – the whole point of it is that it is implemented without exceptions so that it is fast. In fact the way it is most likely implemented is that internally theParsemethod will callTryParseand then throw an exception if it returnsfalse.In a nutshell, use
Parseif you are sure the value will be valid; otherwise useTryParse.