| introductory-examples/io/o-demo.cs - 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);
}
}