Is there any drawback for omitting .ToString() while converting numeric values to string ?
int i = 1234;
string s;
// Instead of
s = "i is " + i.ToString();
// Writing
s = "i is " + i;
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.
It doesn’t make a difference in this case.
compiles down to
String.Concat has multiple overloads, and I believe that the
Concat(Object, Object)overload is chosen (since the only common ancestor of string and int is object).The internal implementation is this:
If you call
then it chooses the
Concat(String, String)overload since both are strings.So for all practical matters, it’s essentially doing the same anyway – it’s implicitly calling i.ToString().
I usually omit .ToString in cases like the above because it just adds noise.