Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > C# 2012/5.0 General Discussion
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2012/5.0 General Discussion Discussions 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 23rd, 2012, 08:42 PM
Registered User
Points: 27, Level: 1
Points: 27, Level: 1 Points: 27, Level: 1 Points: 27, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
Default Why bother with {0}-ish string formatting?

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.

Thanks for any input...
Reply With Quote
  #2 (permalink)  
Old December 25th, 2012, 07:33 AM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Austin, Tx.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old December 25th, 2012, 05:00 PM
Registered User
Points: 27, Level: 1
Points: 27, Level: 1 Points: 27, Level: 1 Points: 27, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #4 (permalink)  
Old December 26th, 2012, 06:22 PM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Location: NYC, NY
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Why the {0} conventions. .

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hey I am here again to bother you :) nawar youssef BOOK: Beginning PHP 5.3 0 November 27th, 2011 12:16 AM
VB questions, around pg 185-ish jefals BOOK: Beginning ASP.NET 4 : in C# and VB 1 November 20th, 2010 12:05 PM
String Formatting sumith ASP.NET 2.0 Basics 1 October 3rd, 2007 07:35 AM
String formatting MargateFan XSLT 4 May 5th, 2006 04:54 AM



All times are GMT -4. The time now is 01:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.