본문 바로가기

Software/C#.Net

The System.Console Class

MSDN
Most of methods are static
WriteLine()        pumps a text strings including a carriage return to the output stream
 Write()             method pumps text to the output stream without a carriage return
ReadLine()        allows you to receive information from the input stream up until the Enter key is pressed
Read()              used to capture a single character from the input stream
.NET Numerical Format Characters
---------------------------------------------------------------------------------------------------------------------------
String Format Character          Meaning in Life 
C or c       Used to format currency. By default, the flag will prefix the local cultural symbol (a dollar sign [$] for U.S. English). 
D or d                                   Used to format decimal numbers. This flag may also specify the minimum number of digits used to pad the value. 
E or e                                    Used for exponential notation. Casing controls whether the exponential constant is uppercase (E) or lowercase (e). 
F or f                                     Used for fixed-point formatting. This flag may also specify the minimum number of digits used to pad the value. 
G or g                                   Stands for general. This character can be used to format a number to fixed or exponential format. 
N or n                                   Used for basic numerical formatting (with commas). 
X or x                                   Used for hexadecimal formatting. If you use an uppercase X, your hex format will also contain uppercase characters.
Examples
  
Examples
  Console.WriteLine("The value 99999 in various formats:"); 
  Console.WriteLine("c format: {0:c}", 99999);                      c format: $99,999.00
  Console.WriteLine("d9 format: {0:d9}", 99999);                d9 format: 000099999
  Console.WriteLine("f3 format: {0:f3}", 99999);                  f3 format: 99999.000
  Console.WriteLine("n format: {0:n}", 99999);                     n format: 99,999.00
 
  // Notice that upper- or lowercasing for hex 
  // determines if letters are upper- or lowercase. 
  Console.WriteLine("E format: {0:E}", 99999);                    E format: 9.999900E+004
  Console.WriteLine("e format: {0:e}", 99999);                    e format: 9.999900e+004
  Console.WriteLine("X format: {0:X}", 99999);                   X format: 1869F
  Console.WriteLine("x format: {0:x}", 99999);                   x format: 1869f