Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Console.WriteLine Method (Boolean)

Writes the text representation of the specified Boolean value, followed by the current line terminator, to the standard output stream.

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

'Declaration
Public Shared Sub WriteLine ( _
	value As Boolean _
)
'Usage
Dim value As Boolean

Console.WriteLine(value)
public static void WriteLine (
	boolean value
)
public static function WriteLine (
	value : boolean
)
Not applicable.

Parameters

value

The value to write.

Exception typeCondition

IOException

An I/O error occurred.

The text representation of value is produced by calling the Boolean.ToString method.

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

Imports Microsoft.VisualBasic
Imports System

Public Class TipCalculator
   Private Const tipRate As Double = 0.18
   
   Public Shared Sub Main()
      System.Environment.ExitCode = Calculator(System.Environment.GetCommandLineArgs())
   End Sub
   
   Public Shared Function Calculator(args() As String) As Integer
      Dim billTotal As Double
      If args.Length < 2 Then
         Console.WriteLine("usage: TIPCALC total")
         Return 1
      Else
         Try
            billTotal = Double.Parse(args(1))
         Catch
            Console.WriteLine("usage: TIPCALC total")
            Return 1
         End Try
         Dim tip As Double = billTotal * tipRate
         Console.WriteLine()
         Console.WriteLine("Bill total:" & vbTab & "{0,8:c}", billTotal)
         Console.WriteLine("Tip total/rate:" & vbTab & "{0,8:c} ({1:p1})", tip, tipRate)
         Console.WriteLine("".PadRight(24, "-"c))
         Console.WriteLine("Grand total:" & vbTab & "{0,8:c}", billTotal + tip)
         Return 0
      End If
   End Function 'Main
End Class 'TipCalculator

'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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft