dcsimg
 

Submitted by: Srinath M S(srinath_ms@yahoo.com)

Friday Apr 20th 2018 by Srinath M S

Language: .NET, Level: Intermediate: - The formatting for the data written to the console using the console.write or console.writeline commands can be difficult to read. See how C# allows you to insert additional spaces to fix that problem.

We use string.format to format the data written to the console using the console.write or console.writeline commands. However, it isn't indented well to make it readable. C# allows you to bridge this gap by supporting the addition of spaces and thus providing the formatted and indented output.

for (int counter=0 ; counter  {
Console.WriteLine(string.Format("Collection Key: {0,-5} Value: {1,5}"), collection[counter].key, collection[counter].value);
}

As you already know, the numbers 0 and 1 are used to position the value of the variables in the formatted response string. The numbers -5 and 5 allow you to left align and right align the text within 5 spaces.

Home
Mobile Site | Full Site