Relationship with ToString

suggest change

While the String.Format() method is certainly useful in formatting data as strings, it may often be a bit overkill, especially when dealing with a single object as seen below :

String.Format("{0:C}", money);  // yields "$42.00"

An easier approach might be to simply use the ToString() method available on all objects within C#. It supports all of the same standard and custom formatting strings, but doesn’t require the necessary parameter mapping as there will only be a single argument :

money.ToString("C");  // yields "$42.00"

Caveats & Formatting Restrictions

While this approach may be simpler in some scenarios, the ToString() approach is limited with regards to adding left or right padding like you might do within the String.Format() method :

String.Format("{0,10:C}", money);  // yields "    $42.00"

In order to accomplish this same behavior with the ToString() method, you would need to use another method like PadLeft() or PadRight() respectively :

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


String Format:
* Relationship with ToString

Table Of Contents
11 String Format
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
135 Pointers
147 C# Script