tags:

views:

101

answers:

4

{0,-12} is the part i'm curious about..

I'm looking at this example

    Console.WriteLine("{0,-12} {1}", sqlReader.GetName(0),
                                         sqlReader.GetName(1));

Cheers :)

+2  A: 

It is for string alignment.

http://www.csharp-examples.net/align-string-with-spaces/

Daniel A. White
+6  A: 

The "0" part of "{0,-12}" says to take the first argument (sqlReader.GetName(0)). The "-12" part indicates that the string should be left-aligned, and that it should use 12 spaces (the field width). If the data doesn't use all 12 spaces, it will fill in the remaining spaces to make the string a total width of 12.

You can see all the options here: http://msdn.microsoft.com/en-us/library/txafckwd.aspx

Andy White
+3  A: 

from msdn

{index[,length][:formatString]}

length: The minimum number of characters in the string representation of the parameter. If positive, the parameter is right-aligned; if negative, it is left-aligned.

moi_meme
+2  A: 

The -12 part of the format specifier tells the formatter to write the content in a space 12 characters wide with left-justification. If the content is fewer than 12 characters, the rightmost positions will be filled with spaces. IF it's more than 12 characters, the text will just spill over. I'm guessing that the example is trying to make neatly formatted columnar data:

0123456789012345678901234567890
ShortText   OtherData
LongerText  OtherData
ReallyLongTextOtherData
Tim Trout