Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Console.WriteLine Method (Char)

Writes the specified Unicode character, followed by the current line terminator, value to the standard output stream.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static void WriteLine (
	char value
)
public static void WriteLine (
	char value
)
public static function WriteLine (
	value : char
)

Parameters

value

The value to write.

Exception typeCondition

IOException

An I/O error occurred.

For more information about the line terminator, see the Remarks section of the WriteLine method that takes no parameters.

The following code example illustrates the use of the WriteLine method.

// System.Console.WriteLine

using System;
public class TipCalculator {
    private const double tipRate = 0.18;
    public static int Main(string[] args) {
        double billTotal;
        if (args.Length == 0) {
            Console.WriteLine("usage: TIPCALC total");
            return 1;
        }
        else {
            try {
                billTotal = Double.Parse(args[0]);
            }
            catch(FormatException) {
                Console.WriteLine("usage: TIPCALC total");
                return 1;
            }
            double tip = billTotal * tipRate;
            Console.WriteLine();
            Console.WriteLine("Bill total:\t{0,8:c}", billTotal);
            Console.WriteLine("Tip total/rate:\t{0,8:c} ({1:p1})", tip, tipRate);
            Console.WriteLine(("").PadRight(24, '-'));
            Console.WriteLine("Grand total:\t{0,8:c}", billTotal + tip);
            return 0;
        }
    }
}

/*
Example Output:
---------------

Bill total:       $52.23
Tip total/rate:    $9.40 (18.0 %)
------------------------
Grand total:      $61.63
*/

// System.Console.WriteLine

import System.* ;

public class TipCalculator
{
    private static double tipRate = 0.18;

    public static void main(String[] args)
    {
        double billTotal = 0;

        if (args.length == 0) {
            Console.WriteLine("usage: TIPCALC total");            
        }
        else {

            try {
                billTotal = Double.parseDouble(args[0]);
            }
            catch (FormatException exp)    {
                Console.WriteLine("usage: TIPCALC total");                
            }

            double tip = billTotal * tipRate;

            Console.WriteLine();
            Console.WriteLine("Bill total:\t{0,8}", 
                ((System.Double)billTotal).ToString("c"));
            Console.WriteLine("Tip total/rate:\t{0,8} ({1})", 
                ((System.Double)tip).ToString("c"), 
                ((System.Double)tipRate).ToString("p1"));
            Console.WriteLine("".PadRight(24, '-'));
            Console.WriteLine("Grand total:\t{0,8}",
                ((System.Double)(billTotal + tip)).ToString("c"));                
        }
    } //main
} //TipCalculator

/*
Example Output:
---------------

Bill total:       $52.23
Tip total/rate:    $9.40 (18.0 %)
------------------------
Grand total:      $61.63
*/

// System.Console.WriteLine
import System;
    
const tipRate : Number = 0.18;
var billTotal : Number;
var args : String[] = Environment.GetCommandLineArgs();

if (args.Length != 2) {
    Console.WriteLine("usage: TIPCALC total");
    Environment.Exit(1);
}

try {
    billTotal = Double.Parse(args[1]);
}
catch(FormatException) {
    Console.WriteLine("usage: TIPCALC total");
    Environment.Exit(1);
}

var tip : double = billTotal * tipRate;
Console.WriteLine();
Console.WriteLine("Bill total:\t{0,8:c}", billTotal);
Console.WriteLine("Tip total/rate:\t{0,8:c} ({1:p1})", tip, tipRate);
Console.WriteLine(("").PadRight(24, '-'));
Console.WriteLine("Grand total:\t{0,8:c}", billTotal + tip);

/*
Example Output:
---------------

Bill total:       $52.23
Tip total/rate:    $9.40 (18.0 %)
------------------------
Grand total:      $61.63
*/

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft