what is the difference between these two statements? which is better with respect to performance?
Console.Writeline(i);
Console.Writeline(i.toString());
where i is a string or an integer.
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.
The bottom line is that writing to the console is bound to dominate the performance here – even if you’re redirecting it to some sort of “null” sink.
The difference, IMO, is that
is simpler to read… so that’s what I’d use until I’d proven that using the slightly-less-readable form gave a concrete benefit. In this case, neither form would end up boxing
iwhen it’s an integer, because there’s an overload forWriteLine(int). A slightly more interesting question is between these two lines:The first form will box the integer; the second won’t. The difference in performance? Nothing significant.