Display 4 mandatory and 3 optional arguments using the Console.WriteLine method. : Console Output Format « Development « C# / CSharp Tutorial






using System;

class Sample 
{
    public static void Main() 
    {
    int     arg0 = 1;
    long    arg1 = 1;
    float   arg2 = -3.3F;
    double  arg3 = 5.5D;
    string  opt4 = "optional argument.";
    char    opt5 = 'X';
    bool    opt6 = true;


    Console.WriteLine("Mandatory arguments:\n" +
                      "argument 0: {0}\n" +
                      "argument 1: {1}\n" +
                      "argument 2: {2}\n" +
                      "argument 3: {3}\n\n" +
                      "Optional arguments:\n" +
                      "optional 4: {4}\n" +
                      "optional 5: {5}\n" +
                      "optional 6: {6}\n", 
                      arg0, arg1, arg2, arg3,
                      opt4, opt5, opt6);

    }
}








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.