Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    Demonstrations of Console output in C#.Lecture 2 - slide 16 : 43
Program 1
/* Right, Wrong */

using System;
public class OutputDemo {

// Placeholder syntax: {<argument#>[,<width>][:<format>[<precision>]]} 

  public static void Main(){
    Console.Write(    "Argument number only: {0} {1}\n", 1, 1.1);   
//  Console.WriteLine("Formatting code d: {0:d},{1:d}", 2, 2.2);    

    Console.WriteLine("Formatting codes d and f: {0:d}  {1:f}", 3, 3.3);  
    Console.WriteLine("Field width: {0,10:d}  {1,10:f}", 4, 4.4);  
    Console.WriteLine("Left aligned: {0,-10:d}  {1,-10:f}", 5, 5.5);  
    Console.WriteLine("Precision: {0,10:d5}  {1,10:f5}", 6, 6.6);  
    Console.WriteLine("Exponential: {0,10:e5}  {1,10:e5}", 7, 7.7);  
    Console.WriteLine("Currency: {0,10:c2}  {1,10:c2}", 8, 8.887);   
    Console.WriteLine("General: {0:g}  {1:g}", 9, 9.9);  
    Console.WriteLine("Hexadecimal: {0:x5}", 12); 

    Console.WriteLine("DateTime formatting with F: {0:F}", DateTime.Now);  
    Console.WriteLine("DateTime formatting with G: {0:G}", DateTime.Now);  
    Console.WriteLine("DateTime formatting with T: {0:T}", DateTime.Now);  
  }   
}
 
 
 
 
 
 
 
 
Default formatting.
Run time error, because 2.2 is not an integer.
 
Integer (d) and floating point (f) formatting.
Width 10, right justification.
Width 10, left justification.
Precission 5.
Exponential (e) formatting.
Currency (c) formatting.
General formatting. Similar to default formatting.
Hexadecimal (x) formattting.
 
Full date, long time.
General date, long time.
Long Time.