Demonstrates some of the formatting flags for writing text to the console : Console Input Output « Development Class « C# / C Sharp






Demonstrates some of the formatting flags for writing text to the console

Demonstrates some of the formatting flags for writing text
               to the console
 
/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

/*
    Format.cs. Demonstrates some of the formatting flags for writing text
               to the console.

               Compile this program with the following command line:
                   C:>csc format.cs
*/
namespace nsFormat
{
    using System;
    public class Format
    {
        static readonly double e = 2.71828;
        static void Main()
        {
            Console.WriteLine ("Integer dollar amount: {0,0:C}", 3);
            Console.WriteLine ("Floating dollar amount: {0,0:C}", 3.29);
            Console.WriteLine ("Integer value: {0,0:D5}", 1024);
            Console.WriteLine ("Integer value: {0,0:N5}", 1024742);

            Console.WriteLine ("Integer value: {0,0:N}", 1024742);
            Console.WriteLine ("Integer value: {0,0:N5}", 1024742);
            Console.WriteLine ("Integer value: {0,0:X}", 1024742);
            Console.WriteLine ("Floating point e: {0,0:F3}", e);
            Console.WriteLine ("Floating point e: {0,-8:F5}", e);
            Console.WriteLine ("Floating point e: {0,-8:E2}", e);
            Console.WriteLine ("Floating point e: {0,-8:E}", e);
        }
    }
}

           
         
  








Related examples in the same category

1.Read double and int from console
2.Read a character from the keyboardRead a character from the keyboard
3.Input from the console using ReadLine()Input from the console using ReadLine()
4.Read a string from the keyboard, using Console.In directlyRead a string from the keyboard, using Console.In directly
5.Write to Console.Out and Console.ErrorWrite to Console.Out and Console.Error
6.Output with parameters
7.Illustrates how to read a character entered using the keyboardIllustrates how to read a character entered using the keyboard
8.Illustrates how to read a string entered using the keyboardIllustrates how to read a string entered using the keyboard
9.Read a line from consoleRead a line from console
10.Demonstrates redirecting the Console output to a fileDemonstrates redirecting the Console output to a file
11.Console command-line argumentsConsole command-line arguments
12.Use format commandsUse format commands
13.Redirect Console.OutRedirect Console.Out
14.This program averages a list of numbers entered by the userThis program averages a list of numbers entered by the user
15.Demonstrate various format specifiersDemonstrate various format specifiers
16.While loop and keyboard readingWhile loop and keyboard reading
17.Uses the #, 0 and comma characters to format outputUses the #, 0 and comma characters to format output
18.A simple command line program that reads from the console using Console.Read() and Console.ReadLine()A simple command line program that reads from
    the console using Console.Read() and Console.ReadLine()
19.C# Basic Data TypesC# Basic Data Types
20.C# Hello UniverseC# Hello Universe
21.Terminate a control input
22.Use do while to read console input
23.Use while(true) to read console input
24.Convert input from control to upper case
25.constructs sentences by concatenating user input until the user enters one of the termination characters
26.input a series of numbers separated by commas, parse them into integers and output the sum
27.Console Write