Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone tell me what this means WriteLine("{0,-12}")

Tags:

c#

sql

odbc

{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 :)

like image 982
Matt Avatar asked Apr 13 '10 02:04

Matt


3 Answers

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

like image 177
Andy White Avatar answered Nov 07 '22 21:11

Andy White


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.

like image 3
moi_meme Avatar answered Nov 07 '22 20:11

moi_meme


It is for string alignment.

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

like image 2
Daniel A. White Avatar answered Nov 07 '22 21:11

Daniel A. White