O'Reilly logo
  • Claudio Di Rocco thinks this is interesting:

You can also specify a width for the value, and justify the text within that width, using positive values for right justification and negative values for left justification. To do this, use the format {n,w}, where n is the parameter index and w is the width value:

int i = 940;
int j = 73;
Console.WriteLine(" {0,4}\n+{1,4}\n — — \n {2,4}", i, j, i + j);


Cover of Professional C# 2012 and .NET 4.5


Beispiel für left-justify:
Console.WriteLine(" {0,-4}\n+{1,4}\n — — \n {2,4}", 10, 8635, 10 + 8635);