Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Format the Console.Write Responses

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.


advertisement

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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.

 

Visit the DevX Tip Bank

 





   
Srinath M. S. says: "I would love to leave a footprint in this flat world."
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date