Format Strings in Console.WriteLine method

It adds padding to the left. Very useful for remembering the various string formatting patterns is the following cheat sheet:

.NET String.Format Cheat Sheet

Positive values add padding to the left, negative add padding to the right

Sample                                 Generates
String.Format("[{0, 10}]", "Foo");     [∙∙∙∙∙∙∙Foo]
String.Format("[{0, 5}]", "Foo");      [∙∙Foo]
String.Format("[{0, -5}]", "Foo");     [Foo∙∙]
String.Format("[{0, -10}]", "Foo");    [Foo∙∙∙∙∙∙∙]

Leave a Comment