devxlogo

Format the Console.Write Responses

Format the Console.Write Responses

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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist