Home
Options

Linqpad's Console does not honor column spacing from String.Format()

edited January 2018
Consider the code shown here:

using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("-------------------------------");
Console.WriteLine("First Name | Last Name | Age");
Console.WriteLine("-------------------------------");
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Bill", "Gates", 51));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Edna", "Parker", 114));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Johnny", "Depp", 44));
Console.WriteLine("-------------------------------");
Console.ReadKey();
}
}
}
In Visual studio, these would be formatted as text columns. But in linqpad, this does not work correctly. It appears to be because each character does not get the same amount of space in the console. E.G. a non monospaced font.

I stole this example from http://www.csharp-examples.net/align-string-with-spaces/

Comments

  • Options
    edited January 2018
    You can do a style sheet customization via Edit, Preferences, Stylesheet: Custom, Launch Editor:

    image
    body {
    	font-family: Consolas;
    }
    Note that the result panel is a richt text window and not a console. If you want to run console applications, you can execute the .linq file using lprun.exe (part of LINQPad):
    C:\Temp>lprun Query1.linq
    -------------------------------
    First Name | Last Name | Age
    -------------------------------
    Bill | Gates | 51
    Edna | Parker | 114
    Johnny | Depp | 44
    -------------------------------

    C:\Temp>
Sign In or Register to comment.