Home  |  Delphi .net Home  |  System.Console  |  WriteLine Method
  
WriteLine  
Method  
Writes line terminated data to the Standard Output Stream
Console Class
System NameSpace
CF1.  Procedure WriteLine ; Static;
NotCF2.  Procedure WriteLine ( Boolean ) ; Static;
CF3.  Procedure WriteLine ( Char ) ; Static;
CF4.  Procedure WriteLine ( Value : Array of Char ) ; Static;
NotCF5.  Procedure WriteLine ( Value : Single ) ; Static;
NotCF6.  Procedure WriteLine ( Value : Double ) ; Static;
NotCF7.  Procedure WriteLine ( Value : Decimal ) ; Static;
CF8.  Procedure WriteLine ( Value : Int32 ) ; Static;
NotCF9.  Procedure WriteLine ( Value : Int64 ) ; Static;
NotCF10.  Procedure WriteLine ( Value : UInt32 ) ; Static;
NotCF11.  Procedure WriteLine ( Value : UInt64 ) ; Static;
CF12.  Procedure WriteLine ( Value : String ) ; Static;
CF13.  Procedure WriteLine ( Value : Object ) ; Static;
CF14.  Procedure WriteLine ( Format : String; Value : Object ) ; Static;
CF15.  Procedure WriteLine ( Format : String; Value : Object; Value : Object ) ; Static;
CF16.  Procedure WriteLine ( Format : String; Value : Object; Value : Object; Value : Object ) ;
CF17.  Procedure WriteLine ( Format : String; Values : Array of Object ) ; Static;
NotCF18.  Procedure WriteLine ( Chars : Array of Char; Start : Integer; Count : Integer ) ; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Writes the specified data, followed by the current line terminator, to the standard output stream.
 
The line terminator characters are determined by the System.Console.Out's TextWriter.NewLine operator.
 
Format provides a very rich and well organised set of formatting options for the integer, decimal, datetime and enumeration data types.
 
The data parameters to the Format syntax may be passed as a discrete set of up to 3 variables, or as an unlimited array of objects.
 
The formatting string comprises 0, 1 or more sections of plain text, interspersed with formatting string sections. These formatting sections are delimited by {} brackets.
 
You may use { and } in the plain text by repeating each : {{ and }} respectively.
 
The formatting sections each have the following general syntax :
 
{Index[,Width][:Formatting]}
 
Where :
 
Index Is the parameter number (0 indexed)
Width Defines the whole field width
Formatting Defines a specific format to use

 
The formatting value has the following syntax :
 
FormattingChar[Precision]
 
Unlike the non-.Net Delphi Format Run Time Library function, the .Net formatting character set is split into 3 groups, applicable to the general data type. For example, the D formatting character applied to a number yields a Decimal string, but applied to a DateTime will yield a LongDate string.
 
The optional Precision forces the number of decimal places or significant digits as appropriate.
 
1. Number formatting characters
 
C or c Currency such as ?1,234.56
D or d Integer formatting such as 123456
E or e Exponential (Scientific) such as 1.23456E+003
F or f Fixed Point such as 1234.56
G or g General : type dependent
N or n Number : -d,ddd,ddd.ddd... format
P or p Percent such as 69.5%
R or r Round-trip - guarantees reverse formatting
X or x Hex such as E06FC (using X) or e06fc (using x)

 
2. DateTime formatting characters
 
Short Date, such as : 24/08/2004
Long date, such as 24 August 2004
Short time, such as 12:23
Long time, such as 12:23:45
Full datetime, such as 24 August 2004 12:23
Full datetime, such as 24 August 2004 12:23:45
General datetime, such as 24/08/2004 12:23
General datetime, such as 24/08/2004 12:23:45
M or m Month, such as 24 August
R or r Culture independant, such as Tue 24 August 2004 12:23:45 GMT
Sortable datetime, such as 2004-08-24T12:23:45
Universal sortable datetime
Y or y Year plus month, such as August 2004

 
3. Enumeration formatting characters
 
Decimal
Fixed
General
Hex
Notes
The UInt32 and UInt64 versions of the method are not CLS (Common Language Specification) compliant.

Static methods are not methods of an object - they are simply class functions or procedures available at any time.
References
TextWriter
Microsoft MSDN Links
System
System.Console
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  bool   : Boolean;
  letter : Char;
  number : Single;

begin
  bool   := true;
  letter := 'Z';
  number := 123;

  Console.WriteLine(bool);
  Console.WriteLine(letter);
  Console.WriteLine(number);
  Console.WriteLine('Hello cruel World');

  Console.ReadLine;
end.
   True
   Z
   123
   Hello cruel World
Illustrating the formatting character options
program Project1;
{$APPTYPE CONSOLE}

var
  decNumber : Decimal;
  intNumber : Integer;
  floatNum  : Single;
  when      : DateTime;
  enum      : system.DayOfWeek;

begin
  decNumber := 123456.789;
  intNumber := 123456789;
  floatNum  := 0.25;
  when      := DateTime.Now;
  enum      := DayOfWeek.Tuesday;

  Console.WriteLine('Number formatting examples :');
  Console.WriteLine;

  Console.WriteLine('C : Currency       : {0:C}',
                    decNumber);
  Console.WriteLine('D : Integer (D)    : {0:D}',
                    System.Object (intNumber));
  Console.WriteLine('E : Exponential    : {0:E}',
                    decNumber);
  Console.WriteLine('F : Fixed          : {0:F}',
                    decNumber);
  Console.WriteLine('G : General        : {0:G}',
                    decNumber);
  Console.WriteLine('N : Number         : {0:N}',
                    decNumber);
  Console.WriteLine('P : Percent        : {0:P}',
                    System.Object (floatNum));
  Console.WriteLine('R : Round-trip     : {0:R}',
                    System.Object (floatNum));
  Console.WriteLine('X : Hexadecimal (X): {0:X}',
                    System.Object (intNumber));
  Console.WriteLine('x : Hexadecimal (x): {0:x}',
                    System.Object (intNumber));

  Console.WriteLine;
  Console.WriteLine('DateTime formatting examples :');
  Console.WriteLine;

  Console.WriteLine('d : Short Date     : {0:d}', when);
  Console.WriteLine('D : Long Date      : {0:D}', when);
  Console.WriteLine('t : Short Time     : {0:t}', when);
  Console.WriteLine('T : Long Time      : {0:T}', when);
  Console.WriteLine('f : Full date      : {0:f}', when);
  Console.WriteLine('F : Long full date : {0:F}', when);
  Console.WriteLine('g : General        : {0:g}', when);
  Console.WriteLine('G : Long general   : {0:G}', when);
  Console.WriteLine('M : Month          : {0:M}', when);
  Console.WriteLine('R : RFC1123        : {0:R}', when);
  Console.WriteLine('s : Sortable       : {0:s}', when);
  Console.WriteLine('u : Universal sort : {0:u}', when);
  Console.WriteLine('Y : Year           : {0:Y}', when);

  Console.WriteLine;
  Console.WriteLine('Enumeration formatting examples :');
  Console.WriteLine;

  Console.WriteLine('G : General        : {0:G}', enum);
  Console.WriteLine('F : Fixed          : {0:F}', enum);
  Console.WriteLine('D : Decimal        : {0:D}', enum);
  Console.WriteLine('X : Hexadecimal (X): {0:X}', enum);
  Console.WriteLine('x : Hexadecimal (x): {0:x}', enum);

  Console.ReadLine;
end.
   Number formatting examples :
  
   C : Currency       : ?123,456.79
   D : Integer (D)    : 123456789
   E : Exponential    : 1.234568E+005
   F : Fixed          : 123456.79
   G : General        : 123456.789
   N : Number         : 123,456.79
   P : Percent        : 25.00 %
   R : Round-trip     : 0.25
   X : Hexadecimal (X): 75BCD15
   x : Hexadecimal (x): 75bcd15
  
   DateTime formatting examples :
  
   d : Short Date     : 02/09/2004
   D : Long Date      : 02 September 2004
   t : Short Time     : 11:14
   T : Long Time      : 11:14:59
   f : Full date      : 02 September 2004 11:14
   F : Long full date : 02 September 2004 11:14:59
   g : General        : 02/09/2004 11:14
   G : Long general   : 02/09/2004 11:14:59
   M : Month          : 02 September
   R : RFC1123        : Thu, 02 Sep 2004 11:14:59 GMT
   s : Sortable       : 2004-09-02T11:14:59
   u : Universal sort : 2004-09-02 11:14:59Z
   Y : Year           : September 2004
  
   Enumeration formatting examples :
  
   G : General        : Tuesday
   F : Fixed          : Tuesday
   D : Decimal        : 2
   X : Hexadecimal (X): 00000002
   x : Hexadecimal (x): 00000002
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author