0

I am learning ADO.NET and now I am trying to understand the SqlDataReader. I am trying to learning by using this tutorial and I am facing some difficulties now in understanding the following part of the code mentioned HERE:

while (rdr.Read())
    {
        // get the results of each column
        string contact = (string)rdr["ContactName"];
        string company = (string)rdr["CompanyName"];
        string city    = (string)rdr["City"];

        // print out the results
        Console.Write("{0,-25}", contact);
        Console.Write("{0,-20}", city);
        Console.Write("{0,-25}", company);
        Console.WriteLine();
    }

I want to understand the meaning of "{0, -25}"

user1395782
  • 107
  • 3
  • 17

3 Answers3

2

That is a format specifier for .NET Console.Write(). See documentation explaining here: http://msdn.microsoft.com/en-us/library/9xdyw6yk.aspx

dkamins
  • 21,450
  • 7
  • 55
  • 59
2

This means that the WriteLine method schould print the value of the first parameter, in your case contact, to a width of 25 characters. The minus in front of the 25 indicates a left justified output.

Mithrandir
  • 24,869
  • 6
  • 50
  • 66
0

IN SqlDataReader, it reads record from database based on query. sqlDataReader read record at a time single row. it means rdr["ContactName"] is one value and it read and move to string contact and so on every fields. It fetch all record in while loop. And Console.Write("{0,-25}", contact) is used to format output.

Manoj Savalia
  • 1,402
  • 3
  • 13
  • 36