Formatting of a text output in C# console application

C# provides us ways to format our text output in console applications. Here’s the example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApplication6
{
    class Program
    {
   
        static void Main(string[] args)
        {
            int num1=23232, num2=4233;

            Console.WriteLine(" {0,10}\n+{1,10}\n ---\n {2,10}", num1,num2,num1+num2);
            Console.WriteLine("\nBelow is example of non-formatted data\n");
      
            Console.WriteLine(" {0}\n+{1}\n ---\n {2}", num1, num2, num1 + num2);
        }
    }
}

When we write {0,10}, this means, a space of 10 characters is reserved for the 1st variable to be displayed at console

Add a Comment

Your email address will not be published. Required fields are marked *