Use format commands: indicate the parameter sequence : Console Output Format « Development « C# / CSharp Tutorial






using System; 
 
class Example {    
  public static void Main() {    
    int i; 
 
    Console.WriteLine("Value\tSquared\tCubed"); 
 
    for(i = 1; i < 10; i++) 
      Console.WriteLine("{0}\t{1}\t{2}",  
                        i, i*i, i*i*i); 
  }    
}
Value   Squared Cubed
1       1       1
2       4       8
3       9       27
4       16      64
5       25      125
6       36      216
7       49      343
8       64      512
9       81      729








14.4.Console Output Format
14.4.1.Format: Allignment
14.4.2.Format: Currency
14.4.3.Format: {0,-10:G}
14.4.4.Format: {0,-10}
14.4.5.Format: {0,-10:F4} -- Fixed Point, 4 decimal places
14.4.6.Format: {0,-10:C} -- Currency
14.4.7.Format: {0,-10:E3} -- Sci. Notation, 3 dec places
14.4.8.Format: {0,-10:x} -- Hexadecimal integer
14.4.9.Use format commands: indicate the parameter sequence
14.4.10.Use the C format specifier to output dollars and cents.
14.4.11.Format double value
14.4.12.Numeric formatting specifiers
14.4.13.Display 4 mandatory and 3 optional arguments using the Console.WriteLine method.