When I use the following code it feels like I’m going wrong somewhere.
object obj = 1;
int i = int.Parse(obj.ToString());
Is there a simpler way?
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.
Well, what is actually in the
obj? If it is just a boxedint, then simply cast to unbox:For less predetermined content you might also try:
which will handle a number of scenarios and doesn’t add an extra
stringin the mix.