C# 2012/5.0 General DiscussionDiscussions about the C# 2012 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# 2012/5.0 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Why bother with Console.Write("{0} ", number); instead of Console.Write(number.ToString());?
Or examples where there are several variables and strings being strung together - surely string concatenation is clearer and faster to write, and if you're doing it multiple times you can consider a StringBuilder.
Interesting question. Since .ToString() also gives you formatting capabilities. My guess is that Console.Write() uses .ToString() under the hood, and is simply for convenience as it mimics the traditional 'C' printf() function.
Thanks... I was really just wondering about the use of bracketed numbers to refer to the comma-separated list of variables. I guess that people think it makes it easier to read.
Another advantage to using this would be repeating the arguments like: Console.WriteLine("....{0}...{1}...{0}..{2}...{0}. .{1}", myVar, hisVar, herVar);
Imagine how much more you would have to type otherwise.