Is better to use the below statement
Convert.ToInt32(“0” + stringValue)
If not then why?
I know that it is better to user int.TryParse() function, which is better, but what about the above statement.
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.
Better than what?
Personally, I think that using
Convert.ToInt32("0" + stringValue)is an anti-pattern.It doesn’t provide anything useful, since:
Just use
Convert.ToInt32(stringValue)directly, orint.TryParseif you don’t want to have exception handling in place.