Console.WriteLine Método

Definição

Grava os dados especificados, seguido pelo terminador de linha atual para o fluxo de saída padrão.

Sobrecargas

WriteLine(String, Object, Object)

Grava a representação de texto dos objetos especificados, seguido de um terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

WriteLine(String)

Grava o valor de cadeia de caracteres especificado, seguido pelo terminador de linha atual para o fluxo de saída padrão.

WriteLine(Char[], Int32, Int32)

Grava a submatriz especificada de caracteres Unicode, seguida por um terminador de linha atual, no fluxo de saída padrão.

WriteLine(String, Object[])

Grava a representação de texto da matriz de objetos especificada, seguido por um terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

WriteLine(String, Object)

Grava a representação de texto do objeto especificado, seguido de um terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

WriteLine(UInt64)

Grava a representação de texto do valor inteiro sem sinal de 64 bits especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

WriteLine(UInt32)

Grava a representação de texto do valor inteiro sem sinal de 32 bits especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

WriteLine(Single)

Grava a representação de texto do valor de ponto flutuante de precisão simples, seguido do terminador de linha atual, no fluxo de saída padrão.

WriteLine(Decimal)

Grava a representação de texto do valor Decimal especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

WriteLine(Int64)

Grava a representação de texto do valor inteiro com sinal de 64 bits, seguido do terminador de linha atual, no fluxo de saída padrão.

WriteLine(Int32)

Grava a representação de texto do valor inteiro com sinal de 32 bits, seguido do terminador de linha atual, no fluxo de saída padrão.

WriteLine(Double)

Grava a representação de texto do valor de ponto flutuante de precisão dupla, seguido do terminador de linha atual, no fluxo de saída padrão.

WriteLine(Char[])

Grava a matriz especificada de caracteres Unicode, seguida por um terminador de linha atual, no fluxo de saída padrão.

WriteLine(Char)

Grava o caractere Unicode especificado, seguido por um terminador de linha atual, valor para o fluxo de saída padrão.

WriteLine(Boolean)

Grava a representação de texto do valor booliano especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

WriteLine()

Grava o terminador de linha atual no fluxo de saída padrão.

WriteLine(String, Object, Object, Object)

Grava a representação de texto dos objetos especificados, seguido de um terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

WriteLine(Object)

Grava a representação de texto do objeto especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

WriteLine(String, Object, Object, Object, Object)

Grava a representação de texto dos objetos especificados e a lista de parâmetros de tamanho variável, seguido do terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

Comentários

O terminador de linha padrão é uma cadeia de caracteres cujo valor é um retorno de carro seguido por um feed de linha ("\r\n" em C# ou vbCrLf em Visual Basic). Você pode alterar o terminador de linha definindo a TextWriter.NewLine propriedade da propriedade como outra cadeia de Out caracteres.

WriteLine(String, Object, Object)

Grava a representação de texto dos objetos especificados, seguido de um terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

public:
 static void WriteLine(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1);
public static void WriteLine (string format, object? arg0, object? arg1);
public static void WriteLine (string format, object arg0, object arg1);
static member WriteLine : string * obj * obj -> unit
Public Shared Sub WriteLine (format As String, arg0 As Object, arg1 As Object)

Parâmetros

format
String

Uma cadeia de caracteres de formato de composição.

arg0
Object

O primeiro objeto a ser gravado usando-se format.

arg1
Object

O segundo objeto a ser gravado usando format.

Exceções

Ocorreu um erro de E/S.

format é null.

A especificação de formato em format é inválida.

Exemplos

O exemplo a seguir demonstra os especificadores de formatação padrão para números, datas e enumerações.

// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.

using namespace System;

public enum class Color {Yellow = 1, Blue, Green};

int main() 
{
    DateTime thisDate = DateTime::Now;
    Console::Clear();

    // Format a negative integer or floating-point number in various ways.
    Console::WriteLine("Standard Numeric Format Specifiers");
    Console::WriteLine(
        "(C) Currency: . . . . . . . . {0:C}\n" +
        "(D) Decimal:. . . . . . . . . {0:D}\n" +
        "(E) Scientific: . . . . . . . {1:E}\n" +
        "(F) Fixed point:. . . . . . . {1:F}\n" +
        "(G) General:. . . . . . . . . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(N) Number: . . . . . . . . . {0:N}\n" +
        "(P) Percent:. . . . . . . . . {1:P}\n" +
        "(R) Round-trip: . . . . . . . {1:R}\n" +
        "(X) Hexadecimal:. . . . . . . {0:X}\n",
        -123, -123.45f); 

    // Format the current date in various ways.
    Console::WriteLine("Standard DateTime Format Specifiers");
    Console::WriteLine(
        "(d) Short date: . . . . . . . {0:d}\n" +
        "(D) Long date:. . . . . . . . {0:D}\n" +
        "(t) Short time: . . . . . . . {0:t}\n" +
        "(T) Long time:. . . . . . . . {0:T}\n" +
        "(f) Full date/short time: . . {0:f}\n" +
        "(F) Full date/long time:. . . {0:F}\n" +
        "(g) General date/short time:. {0:g}\n" +
        "(G) General date/long time: . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(M) Month:. . . . . . . . . . {0:M}\n" +
        "(R) RFC1123:. . . . . . . . . {0:R}\n" +
        "(s) Sortable: . . . . . . . . {0:s}\n" +
        "(u) Universal sortable: . . . {0:u} (invariant)\n" +
        "(U) Universal full date/time: {0:U}\n" +
        "(Y) Year: . . . . . . . . . . {0:Y}\n", 
        thisDate);

    // Format a Color enumeration value in various ways.
    Console::WriteLine("Standard Enumeration Format Specifiers");
    Console::WriteLine(
        "(G) General:. . . . . . . . . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
        "(D) Decimal number: . . . . . {0:D}\n" +
        "(X) Hexadecimal:. . . . . . . {0:X}\n", 
        Color::Green);       

};


/*
This code example produces the following results:

Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85

Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004

Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003

*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.

using System;
class Sample
{
    enum Color {Yellow = 1, Blue, Green};
    static DateTime thisDate = DateTime.Now;

    public static void Main()
    {
        Console.Clear();

        // Format a negative integer or floating-point number in various ways.
        Console.WriteLine("Standard Numeric Format Specifiers");
        Console.WriteLine(
            "(C) Currency: . . . . . . . . {0:C}\n" +
            "(D) Decimal:. . . . . . . . . {0:D}\n" +
            "(E) Scientific: . . . . . . . {1:E}\n" +
            "(F) Fixed point:. . . . . . . {1:F}\n" +
            "(G) General:. . . . . . . . . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(N) Number: . . . . . . . . . {0:N}\n" +
            "(P) Percent:. . . . . . . . . {1:P}\n" +
            "(R) Round-trip: . . . . . . . {1:R}\n" +
            "(X) Hexadecimal:. . . . . . . {0:X}\n",
            -123, -123.45f);

        // Format the current date in various ways.
        Console.WriteLine("Standard DateTime Format Specifiers");
        Console.WriteLine(
            "(d) Short date: . . . . . . . {0:d}\n" +
            "(D) Long date:. . . . . . . . {0:D}\n" +
            "(t) Short time: . . . . . . . {0:t}\n" +
            "(T) Long time:. . . . . . . . {0:T}\n" +
            "(f) Full date/short time: . . {0:f}\n" +
            "(F) Full date/long time:. . . {0:F}\n" +
            "(g) General date/short time:. {0:g}\n" +
            "(G) General date/long time: . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(M) Month:. . . . . . . . . . {0:M}\n" +
            "(R) RFC1123:. . . . . . . . . {0:R}\n" +
            "(s) Sortable: . . . . . . . . {0:s}\n" +
            "(u) Universal sortable: . . . {0:u} (invariant)\n" +
            "(U) Universal full date/time: {0:U}\n" +
            "(Y) Year: . . . . . . . . . . {0:Y}\n",
            thisDate);

        // Format a Color enumeration value in various ways.
        Console.WriteLine("Standard Enumeration Format Specifiers");
        Console.WriteLine(
            "(G) General:. . . . . . . . . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
            "(D) Decimal number: . . . . . {0:D}\n" +
            "(X) Hexadecimal:. . . . . . . {0:X}\n",
            Color.Green);
    }
}
/*
This code example produces the following results:

Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
    (default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85

Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
    (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004

Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
    (default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003

*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.

open System

type Color = 
    | Yellow = 1
    | Blue = 2
    | Green = 3

let thisDate = DateTime.Now

Console.Clear()

// Format a negative integer or floating-point number in various ways.
Console.WriteLine "Standard Numeric Format Specifiers"
Console.WriteLine(
    "(C) Currency: . . . . . . . . {0:C}\n" +
    "(D) Decimal:. . . . . . . . . {0:D}\n" +
    "(E) Scientific: . . . . . . . {1:E}\n" +
    "(F) Fixed point:. . . . . . . {1:F}\n" +
    "(G) General:. . . . . . . . . {0:G}\n" +
    "    (default):. . . . . . . . {0} (default = 'G')\n" +
    "(N) Number: . . . . . . . . . {0:N}\n" +
    "(P) Percent:. . . . . . . . . {1:P}\n" +
    "(R) Round-trip: . . . . . . . {1:R}\n" +
    "(X) Hexadecimal:. . . . . . . {0:X}\n",
    -123, -123.45f)

// Format the current date in various ways.
Console.WriteLine "Standard DateTime Format Specifiers"
Console.WriteLine(
    "(d) Short date: . . . . . . . {0:d}\n" +
    "(D) Long date:. . . . . . . . {0:D}\n" +
    "(t) Short time: . . . . . . . {0:t}\n" +
    "(T) Long time:. . . . . . . . {0:T}\n" +
    "(f) Full date/short time: . . {0:f}\n" +
    "(F) Full date/long time:. . . {0:F}\n" +
    "(g) General date/short time:. {0:g}\n" +
    "(G) General date/long time: . {0:G}\n" +
    "    (default):. . . . . . . . {0} (default = 'G')\n" +
    "(M) Month:. . . . . . . . . . {0:M}\n" +
    "(R) RFC1123:. . . . . . . . . {0:R}\n" +
    "(s) Sortable: . . . . . . . . {0:s}\n" +
    "(u) Universal sortable: . . . {0:u} (invariant)\n" +
    "(U) Universal full date/time: {0:U}\n" +
    "(Y) Year: . . . . . . . . . . {0:Y}\n",
    thisDate)

// Format a Color enumeration value in various ways.
Console.WriteLine "Standard Enumeration Format Specifiers"
Console.WriteLine(
    "(G) General:. . . . . . . . . {0:G}\n" +
    "    (default):. . . . . . . . {0} (default = 'G')\n" +
    "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
    "(D) Decimal number: . . . . . {0:D}\n" +
    "(X) Hexadecimal:. . . . . . . {0:X}\n",
    Color.Green)


// This code example produces the following results:
//
// Standard Numeric Format Specifiers
// (C) Currency: . . . . . . . . ($123.00)
// (D) Decimal:. . . . . . . . . -123
// (E) Scientific: . . . . . . . -1.234500E+002
// (F) Fixed point:. . . . . . . -123.45
// (G) General:. . . . . . . . . -123
//     (default):. . . . . . . . -123 (default = 'G')
// (N) Number: . . . . . . . . . -123.00
// (P) Percent:. . . . . . . . . -12,345.00 %
// (R) Round-trip: . . . . . . . -123.45
// (X) Hexadecimal:. . . . . . . FFFFFF85
//
// Standard DateTime Format Specifiers
// (d) Short date: . . . . . . . 6/26/2004
// (D) Long date:. . . . . . . . Saturday, June 26, 2004
// (t) Short time: . . . . . . . 8:11 PM
// (T) Long time:. . . . . . . . 8:11:04 PM
// (f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
// (F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
// (g) General date/short time:. 6/26/2004 8:11 PM
// (G) General date/long time: . 6/26/2004 8:11:04 PM
//     (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
// (M) Month:. . . . . . . . . . June 26
// (R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
// (s) Sortable: . . . . . . . . 2004-06-26T20:11:04
// (u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
// (U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
// (Y) Year: . . . . . . . . . . June, 2004
//
// Standard Enumeration Format Specifiers
// (G) General:. . . . . . . . . Green
//     (default):. . . . . . . . Green (default = 'G')
// (F) Flags:. . . . . . . . . . Green (flags or integer)
// (D) Decimal number: . . . . . 3
// (X) Hexadecimal:. . . . . . . 00000003
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.

Class Sample
   Public Enum Color
      Yellow = 1
      Blue = 2
      Green = 3
   End Enum 'Color
   Private Shared thisDate As DateTime = DateTime.Now
   
   Public Shared Sub Main()
      Console.Clear()

      ' Format a negative integer or floating-point number in various ways.
      Console.WriteLine("Standard Numeric Format Specifiers")
      Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
                        "(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
                        "(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
                        "(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
                        "(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
                        "(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
                        "(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
                        "(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
                        - 123, - 123.45F)

      ' Format the current date in various ways.
      Console.WriteLine("Standard DateTime Format Specifiers")
      Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
                        "(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
                        "(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
                        "(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
                        "(f) Full date/short time: . . {0:f}" & vbCrLf & _
                        "(F) Full date/long time:. . . {0:F}" & vbCrLf & _
                        "(g) General date/short time:. {0:g}" & vbCrLf & _
                        "(G) General date/long time: . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
                        "(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
                        "(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
                        "(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
                        "(U) Universal full date/time: {0:U}" & vbCrLf & _
                        "(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
                        thisDate)

      ' Format a Color enumeration value in various ways.
      Console.WriteLine("Standard Enumeration Format Specifiers")
      Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
                        "(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
                        "(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
                        Color.Green)
   End Sub
End Class
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
'    (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
'    (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
'    (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003
'

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

Esse método usa o recurso de formatação composta do .net para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.

O parâmetro format consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.

A sintaxe de um item de formato é { index[ , alignment][ : formatString] , que especifica um índice obrigatório, o comprimento opcional e o alinhamento do texto formatado e uma cadeia de caracteres opcional de caracteres de especificador de formato que regem como o valor do objeto correspondente } é formatado.

O .NET fornece amplo suporte à formatação, que é descrito em mais detalhes nos tópicos de formatação a seguir.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(String)

Grava o valor de cadeia de caracteres especificado, seguido pelo terminador de linha atual para o fluxo de saída padrão.

public:
 static void WriteLine(System::String ^ value);
public static void WriteLine (string? value);
public static void WriteLine (string value);
static member WriteLine : string -> unit
Public Shared Sub WriteLine (value As String)

Parâmetros

value
String

O valor a ser gravado.

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo altera o terminador de linha de seu valor padrão de "\r\n" ou vbCrLf para "\r\n\r\n" ou vbCrLf + vbCrLf . Em seguida, ele chama os WriteLine() WriteLine(String) métodos e para exibir a saída para o console.

using namespace System;

void main()
{
   array<String^>^ lines = gcnew array<String^> { "This is the first line.", 
                                                  "This is the second line." };
   // Output the lines using the default newline sequence.
   Console::WriteLine("With the default new line characters:");
   Console::WriteLine();
   for each (String^ line in lines)
      Console::WriteLine(line);

   Console::WriteLine();

   // Redefine the newline characters to double space.
   Console::Out->NewLine = "\r\n\r\n";
   // Output the lines using the new newline sequence.
   Console::WriteLine("With redefined new line characters:");
   Console::WriteLine();
   for each (String^ line in lines)
      Console::WriteLine(line);
}
// The example displays the following output:
//       With the default new line characters:
//       
//       This is the first line.
//       This is the second line.
//       
//       With redefined new line characters:
//       
//       
//       
//       This is the first line.
//       
//       This is the second line.
string[] lines = { "This is the first line.",
                   "This is the second line." };
// Output the lines using the default newline sequence.
Console.WriteLine("With the default new line characters:");
Console.WriteLine();
foreach (string line in lines)
   Console.WriteLine(line);

Console.WriteLine();

// Redefine the newline characters to double space.
Console.Out.NewLine = "\r\n\r\n";
// Output the lines using the new newline sequence.
Console.WriteLine("With redefined new line characters:");
Console.WriteLine();
foreach (string line in lines)
   Console.WriteLine(line);

// The example displays the following output:
//       With the default new line characters:
//
//       This is the first line.
//       This is the second line.
//
//       With redefined new line characters:
//
//
//
//       This is the first line.
//
//       This is the second line.
let lines = 
    [ "This is the first line."
      "This is the second line." ]
      
// Output the lines using the default newline sequence.
Console.WriteLine "With the default new line characters:"
Console.WriteLine()
for line in lines do
    Console.WriteLine line

Console.WriteLine()

// Redefine the newline characters to double space.
Console.Out.NewLine <- "\r\n\r\n"
// Output the lines using the new newline sequence.
Console.WriteLine "With redefined new line characters:"
Console.WriteLine()
for line in lines do
    Console.WriteLine line

// The example displays the following output:
//       With the default new line characters:
//
//       This is the first line.
//       This is the second line.
//
//       With redefined new line characters:
//
//
//
//       This is the first line.
//
//       This is the second line.
Module Example
   Public Sub Main()
      Dim lines() As String = { "This is the first line.", _
                                "This is the second line." }
      ' Output the lines using the default newline sequence.
      Console.WriteLine("With the default new line characters:")
      Console.WriteLine()
      For Each line As String In lines
         Console.WriteLine(line)
      Next
      Console.WriteLine()
      
      ' Redefine the newline characters to double space.
      Console.Out.NewLine = vbCrLf + vbCrLf
      ' Output the lines using the new newline sequence.
      Console.WriteLine("With redefined new line characters:")
      Console.WriteLine()
      For Each line As String In lines
         Console.WriteLine(line)
      Next
   End Sub
End Module
' The example displays the following output:
'       With the default new line characters:
'       
'       This is the first line.
'       This is the second line.
'       
'       With redefined new line characters:
'       
'       
'       
'       This is the first line.
'       
'       This is the second line.

Comentários

Se o valor for null , somente o terminador de linha será gravado no fluxo de saída padrão.

Para obter mais informações sobre o terminador de linha, consulte a seção comentários do WriteLine() método.

Confira também

Aplica-se a

WriteLine(Char[], Int32, Int32)

Grava a submatriz especificada de caracteres Unicode, seguida por um terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(cli::array <char> ^ buffer, int index, int count);
public static void WriteLine (char[] buffer, int index, int count);
static member WriteLine : char[] * int * int -> unit
Public Shared Sub WriteLine (buffer As Char(), index As Integer, count As Integer)

Parâmetros

buffer
Char[]

Uma matriz de caracteres Unicode.

index
Int32

A posição inicial em buffer.

count
Int32

O número de caracteres a serem gravados.

Exceções

buffer é null.

index ou count é menor que zero.

A soma de index e count especifica uma posição que não está no buffer.

Ocorreu um erro de E/S.

Comentários

Esse método grava os count caracteres começando na posição index de buffer para o fluxo de saída padrão.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(String, Object[])

Grava a representação de texto da matriz de objetos especificada, seguido por um terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

public:
 static void WriteLine(System::String ^ format, ... cli::array <System::Object ^> ^ arg);
public static void WriteLine (string format, params object?[]? arg);
public static void WriteLine (string format, params object[] arg);
static member WriteLine : string * obj[] -> unit
Public Shared Sub WriteLine (format As String, ParamArray arg As Object())

Parâmetros

format
String

Uma cadeia de caracteres de formato de composição.

arg
Object[]

Uma matriz de objetos a ser gravada usando format.

Exceções

Ocorreu um erro de E/S.

format ou arg é null.

A especificação de formato em format é inválida.

Exemplos

O exemplo a seguir demonstra os especificadores de formatação padrão para números, datas e enumerações.

// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.

using namespace System;

public enum class Color {Yellow = 1, Blue, Green};

int main() 
{
    DateTime thisDate = DateTime::Now;
    Console::Clear();

    // Format a negative integer or floating-point number in various ways.
    Console::WriteLine("Standard Numeric Format Specifiers");
    Console::WriteLine(
        "(C) Currency: . . . . . . . . {0:C}\n" +
        "(D) Decimal:. . . . . . . . . {0:D}\n" +
        "(E) Scientific: . . . . . . . {1:E}\n" +
        "(F) Fixed point:. . . . . . . {1:F}\n" +
        "(G) General:. . . . . . . . . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(N) Number: . . . . . . . . . {0:N}\n" +
        "(P) Percent:. . . . . . . . . {1:P}\n" +
        "(R) Round-trip: . . . . . . . {1:R}\n" +
        "(X) Hexadecimal:. . . . . . . {0:X}\n",
        -123, -123.45f); 

    // Format the current date in various ways.
    Console::WriteLine("Standard DateTime Format Specifiers");
    Console::WriteLine(
        "(d) Short date: . . . . . . . {0:d}\n" +
        "(D) Long date:. . . . . . . . {0:D}\n" +
        "(t) Short time: . . . . . . . {0:t}\n" +
        "(T) Long time:. . . . . . . . {0:T}\n" +
        "(f) Full date/short time: . . {0:f}\n" +
        "(F) Full date/long time:. . . {0:F}\n" +
        "(g) General date/short time:. {0:g}\n" +
        "(G) General date/long time: . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(M) Month:. . . . . . . . . . {0:M}\n" +
        "(R) RFC1123:. . . . . . . . . {0:R}\n" +
        "(s) Sortable: . . . . . . . . {0:s}\n" +
        "(u) Universal sortable: . . . {0:u} (invariant)\n" +
        "(U) Universal full date/time: {0:U}\n" +
        "(Y) Year: . . . . . . . . . . {0:Y}\n", 
        thisDate);

    // Format a Color enumeration value in various ways.
    Console::WriteLine("Standard Enumeration Format Specifiers");
    Console::WriteLine(
        "(G) General:. . . . . . . . . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
        "(D) Decimal number: . . . . . {0:D}\n" +
        "(X) Hexadecimal:. . . . . . . {0:X}\n", 
        Color::Green);       

};


/*
This code example produces the following results:

Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85

Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004

Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003

*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.

using System;
class Sample
{
    enum Color {Yellow = 1, Blue, Green};
    static DateTime thisDate = DateTime.Now;

    public static void Main()
    {
        Console.Clear();

        // Format a negative integer or floating-point number in various ways.
        Console.WriteLine("Standard Numeric Format Specifiers");
        Console.WriteLine(
            "(C) Currency: . . . . . . . . {0:C}\n" +
            "(D) Decimal:. . . . . . . . . {0:D}\n" +
            "(E) Scientific: . . . . . . . {1:E}\n" +
            "(F) Fixed point:. . . . . . . {1:F}\n" +
            "(G) General:. . . . . . . . . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(N) Number: . . . . . . . . . {0:N}\n" +
            "(P) Percent:. . . . . . . . . {1:P}\n" +
            "(R) Round-trip: . . . . . . . {1:R}\n" +
            "(X) Hexadecimal:. . . . . . . {0:X}\n",
            -123, -123.45f);

        // Format the current date in various ways.
        Console.WriteLine("Standard DateTime Format Specifiers");
        Console.WriteLine(
            "(d) Short date: . . . . . . . {0:d}\n" +
            "(D) Long date:. . . . . . . . {0:D}\n" +
            "(t) Short time: . . . . . . . {0:t}\n" +
            "(T) Long time:. . . . . . . . {0:T}\n" +
            "(f) Full date/short time: . . {0:f}\n" +
            "(F) Full date/long time:. . . {0:F}\n" +
            "(g) General date/short time:. {0:g}\n" +
            "(G) General date/long time: . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(M) Month:. . . . . . . . . . {0:M}\n" +
            "(R) RFC1123:. . . . . . . . . {0:R}\n" +
            "(s) Sortable: . . . . . . . . {0:s}\n" +
            "(u) Universal sortable: . . . {0:u} (invariant)\n" +
            "(U) Universal full date/time: {0:U}\n" +
            "(Y) Year: . . . . . . . . . . {0:Y}\n",
            thisDate);

        // Format a Color enumeration value in various ways.
        Console.WriteLine("Standard Enumeration Format Specifiers");
        Console.WriteLine(
            "(G) General:. . . . . . . . . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
            "(D) Decimal number: . . . . . {0:D}\n" +
            "(X) Hexadecimal:. . . . . . . {0:X}\n",
            Color.Green);
    }
}
/*
This code example produces the following results:

Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
    (default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85

Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
    (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004

Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
    (default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003

*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.

open System

type Color = 
    | Yellow = 1
    | Blue = 2
    | Green = 3

let thisDate = DateTime.Now

Console.Clear()

// Format a negative integer or floating-point number in various ways.
Console.WriteLine "Standard Numeric Format Specifiers"
Console.WriteLine(
    "(C) Currency: . . . . . . . . {0:C}\n" +
    "(D) Decimal:. . . . . . . . . {0:D}\n" +
    "(E) Scientific: . . . . . . . {1:E}\n" +
    "(F) Fixed point:. . . . . . . {1:F}\n" +
    "(G) General:. . . . . . . . . {0:G}\n" +
    "    (default):. . . . . . . . {0} (default = 'G')\n" +
    "(N) Number: . . . . . . . . . {0:N}\n" +
    "(P) Percent:. . . . . . . . . {1:P}\n" +
    "(R) Round-trip: . . . . . . . {1:R}\n" +
    "(X) Hexadecimal:. . . . . . . {0:X}\n",
    -123, -123.45f)

// Format the current date in various ways.
Console.WriteLine "Standard DateTime Format Specifiers"
Console.WriteLine(
    "(d) Short date: . . . . . . . {0:d}\n" +
    "(D) Long date:. . . . . . . . {0:D}\n" +
    "(t) Short time: . . . . . . . {0:t}\n" +
    "(T) Long time:. . . . . . . . {0:T}\n" +
    "(f) Full date/short time: . . {0:f}\n" +
    "(F) Full date/long time:. . . {0:F}\n" +
    "(g) General date/short time:. {0:g}\n" +
    "(G) General date/long time: . {0:G}\n" +
    "    (default):. . . . . . . . {0} (default = 'G')\n" +
    "(M) Month:. . . . . . . . . . {0:M}\n" +
    "(R) RFC1123:. . . . . . . . . {0:R}\n" +
    "(s) Sortable: . . . . . . . . {0:s}\n" +
    "(u) Universal sortable: . . . {0:u} (invariant)\n" +
    "(U) Universal full date/time: {0:U}\n" +
    "(Y) Year: . . . . . . . . . . {0:Y}\n",
    thisDate)

// Format a Color enumeration value in various ways.
Console.WriteLine "Standard Enumeration Format Specifiers"
Console.WriteLine(
    "(G) General:. . . . . . . . . {0:G}\n" +
    "    (default):. . . . . . . . {0} (default = 'G')\n" +
    "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
    "(D) Decimal number: . . . . . {0:D}\n" +
    "(X) Hexadecimal:. . . . . . . {0:X}\n",
    Color.Green)


// This code example produces the following results:
//
// Standard Numeric Format Specifiers
// (C) Currency: . . . . . . . . ($123.00)
// (D) Decimal:. . . . . . . . . -123
// (E) Scientific: . . . . . . . -1.234500E+002
// (F) Fixed point:. . . . . . . -123.45
// (G) General:. . . . . . . . . -123
//     (default):. . . . . . . . -123 (default = 'G')
// (N) Number: . . . . . . . . . -123.00
// (P) Percent:. . . . . . . . . -12,345.00 %
// (R) Round-trip: . . . . . . . -123.45
// (X) Hexadecimal:. . . . . . . FFFFFF85
//
// Standard DateTime Format Specifiers
// (d) Short date: . . . . . . . 6/26/2004
// (D) Long date:. . . . . . . . Saturday, June 26, 2004
// (t) Short time: . . . . . . . 8:11 PM
// (T) Long time:. . . . . . . . 8:11:04 PM
// (f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
// (F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
// (g) General date/short time:. 6/26/2004 8:11 PM
// (G) General date/long time: . 6/26/2004 8:11:04 PM
//     (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
// (M) Month:. . . . . . . . . . June 26
// (R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
// (s) Sortable: . . . . . . . . 2004-06-26T20:11:04
// (u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
// (U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
// (Y) Year: . . . . . . . . . . June, 2004
//
// Standard Enumeration Format Specifiers
// (G) General:. . . . . . . . . Green
//     (default):. . . . . . . . Green (default = 'G')
// (F) Flags:. . . . . . . . . . Green (flags or integer)
// (D) Decimal number: . . . . . 3
// (X) Hexadecimal:. . . . . . . 00000003
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.

Class Sample
   Public Enum Color
      Yellow = 1
      Blue = 2
      Green = 3
   End Enum 'Color
   Private Shared thisDate As DateTime = DateTime.Now
   
   Public Shared Sub Main()
      Console.Clear()

      ' Format a negative integer or floating-point number in various ways.
      Console.WriteLine("Standard Numeric Format Specifiers")
      Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
                        "(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
                        "(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
                        "(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
                        "(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
                        "(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
                        "(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
                        "(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
                        - 123, - 123.45F)

      ' Format the current date in various ways.
      Console.WriteLine("Standard DateTime Format Specifiers")
      Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
                        "(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
                        "(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
                        "(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
                        "(f) Full date/short time: . . {0:f}" & vbCrLf & _
                        "(F) Full date/long time:. . . {0:F}" & vbCrLf & _
                        "(g) General date/short time:. {0:g}" & vbCrLf & _
                        "(G) General date/long time: . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
                        "(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
                        "(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
                        "(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
                        "(U) Universal full date/time: {0:U}" & vbCrLf & _
                        "(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
                        thisDate)

      ' Format a Color enumeration value in various ways.
      Console.WriteLine("Standard Enumeration Format Specifiers")
      Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
                        "(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
                        "(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
                        Color.Green)
   End Sub
End Class
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
'    (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
'    (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
'    (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003
'

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

Esse método usa o recurso de formatação composta do .net para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.

O parâmetro format consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.

A sintaxe de um item de formato é { index[ , Alignment] [ : FormatString] } , que especifica um índice obrigatório, o comprimento opcional e o alinhamento do texto formatado e uma cadeia de caracteres opcional de formatos de especificador de formato que governam como o valor do objeto correspondente é formatado.

O .NET fornece amplo suporte de formatação, que é descrito mais detalhadamente nos tópicos de formatação a seguir.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Notas aos Chamadores

Esse método não é chamado pelo código C++. O compilador C++ resolve chamadas para System. console. WriteLine que incluem uma cadeia de caracteres e uma lista de quatro ou mais parâmetros de objeto como uma chamada para WriteLine(String, Object, Object, Object, Object) . Ele resolve chamadas para System. console. WriteLine que incluem uma cadeia de caracteres e uma matriz de objeto como uma chamada para WriteLine(String, Object) .

Confira também

Aplica-se a

WriteLine(String, Object)

Grava a representação de texto do objeto especificado, seguido de um terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

public:
 static void WriteLine(System::String ^ format, System::Object ^ arg0);
public static void WriteLine (string format, object? arg0);
public static void WriteLine (string format, object arg0);
static member WriteLine : string * obj -> unit
Public Shared Sub WriteLine (format As String, arg0 As Object)

Parâmetros

format
String

Uma cadeia de caracteres de formato de composição.

arg0
Object

Um objeto a ser gravado com o uso de format.

Exceções

Ocorreu um erro de E/S.

format é null.

A especificação de formato em format é inválida.

Exemplos

O exemplo a seguir chama o WriteLine(String, Object) método para exibir cinco valores gerados aleatoriamente Boolean .

Random rnd = new Random();
// Generate five random Boolean values.
for (int ctr = 1; ctr <= 5; ctr++) {
   bool bln = rnd.Next(0, 2) == 1;
   Console.WriteLine($"True or False: {bln}");
}

// The example displays an output similar to the following:
//       True or False: False
//       True or False: True
//       True or False: False
//       True or False: False
//       True or False: True
let rnd = Random()

// Generate five random Boolean values.
for _ = 1 to 5 do
    let bln = rnd.Next(0, 2) = 1
    Console.WriteLine $"True or False: {bln}"

// The example displays an output similar to the following:
//       True or False: False
//       True or False: True
//       True or False: False
//       True or False: False
//       True or False: True
Module Example
   Public Sub Main()
      Dim rnd As New Random()
      ' Generate five random Boolean values.
      For ctr As Integer = 1 To 5
         Dim bool As Boolean = Convert.ToBoolean(rnd.Next(0, 2))
         Console.WriteLine("True or False: {0}", bool)
      Next
   End Sub
End Module
' The example displays the following output:
'       True or False: False
'       True or False: True
'       True or False: False
'       True or False: False
'       True or False: True

O exemplo a seguir chama o WriteLine(String, Object) método para exibir a data atual. Observe que o item de formato no format argumento usa a cadeia de caracteres de formato padrão "D" e de hora para exibir a data no formato de data por extenso da cultura atual.

using System;

public class Example
{
   public static void Main()
   {
      Console.WriteLine("Today's date: {0:D}", DateTime.Now);
   }
}
// The example displays output like the following:
//       Today's date: Monday, April 1, 2019
open System

Console.WriteLine $"Today's date: {DateTime.Now:D}"

// The example displays output like the following:
//       Today's date: Tuesday, December 28, 2021
Module Example
   Public Sub Main()
      Console.WriteLine("Today's date: {0:D}", DateTime.Now)
   End Sub
End Module
' The example displays output like the following:
'       Today's date: Friday, April 1, 2016

Comentários

Esse método usa o recurso de formatação composta do .net para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.

O parâmetro format consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.

A sintaxe de um item de formato é { index[ , Alignment] [ : FormatString] } , que especifica um índice obrigatório, o comprimento opcional e o alinhamento do texto formatado e uma cadeia de caracteres opcional de formatos de especificador de formato que governam como o valor do objeto correspondente é formatado.

O .NET fornece amplo suporte de formatação, que é descrito mais detalhadamente nos tópicos de formatação a seguir.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(UInt64)

Importante

Esta API não está em conformidade com CLS.

Grava a representação de texto do valor inteiro sem sinal de 64 bits especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(System::UInt64 value);
[System.CLSCompliant(false)]
public static void WriteLine (ulong value);
[<System.CLSCompliant(false)>]
static member WriteLine : uint64 -> unit
Public Shared Sub WriteLine (value As ULong)

Parâmetros

value
UInt64

O valor a ser gravado.

Atributos

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

A representação de texto de value é produzida chamando o UInt64.ToString método.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(UInt32)

Importante

Esta API não está em conformidade com CLS.

Grava a representação de texto do valor inteiro sem sinal de 32 bits especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(System::UInt32 value);
[System.CLSCompliant(false)]
public static void WriteLine (uint value);
[<System.CLSCompliant(false)>]
static member WriteLine : uint32 -> unit
Public Shared Sub WriteLine (value As UInteger)

Parâmetros

value
UInt32

O valor a ser gravado.

Atributos

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

A representação de texto de value é produzida chamando o UInt32.ToString método.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(Single)

Grava a representação de texto do valor de ponto flutuante de precisão simples, seguido do terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(float value);
public static void WriteLine (float value);
static member WriteLine : single -> unit
Public Shared Sub WriteLine (value As Single)

Parâmetros

value
Single

O valor a ser gravado.

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

A representação de texto de value é produzida chamando o Single.ToString método.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(Decimal)

Grava a representação de texto do valor Decimal especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(System::Decimal value);
public static void WriteLine (decimal value);
static member WriteLine : decimal -> unit
Public Shared Sub WriteLine (value As Decimal)

Parâmetros

value
Decimal

O valor a ser gravado.

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

A representação de texto value de é produzida chamando o método Decimal.ToString .

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(Int64)

Grava a representação de texto do valor inteiro com sinal de 64 bits, seguido do terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(long value);
public static void WriteLine (long value);
static member WriteLine : int64 -> unit
Public Shared Sub WriteLine (value As Long)

Parâmetros

value
Int64

O valor a ser gravado.

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

A representação de texto value de é produzida chamando o método Int64.ToString .

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(Int32)

Grava a representação de texto do valor inteiro com sinal de 32 bits, seguido do terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(int value);
public static void WriteLine (int value);
static member WriteLine : int -> unit
Public Shared Sub WriteLine (value As Integer)

Parâmetros

value
Int32

O valor a ser gravado.

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

A representação de texto value de é produzida chamando o método Int32.ToString .

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(Double)

Grava a representação de texto do valor de ponto flutuante de precisão dupla, seguido do terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(double value);
public static void WriteLine (double value);
static member WriteLine : double -> unit
Public Shared Sub WriteLine (value As Double)

Parâmetros

value
Double

O valor a ser gravado.

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

A representação de texto value de é produzida chamando o método Double.ToString .

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(Char[])

Grava a matriz especificada de caracteres Unicode, seguida por um terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(cli::array <char> ^ buffer);
public static void WriteLine (char[]? buffer);
public static void WriteLine (char[] buffer);
static member WriteLine : char[] -> unit
Public Shared Sub WriteLine (buffer As Char())

Parâmetros

buffer
Char[]

Uma matriz de caracteres Unicode.

Exceções

Ocorreu um erro de E/S.

Comentários

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(Char)

Grava o caractere Unicode especificado, seguido por um terminador de linha atual, valor para o fluxo de saída padrão.

public:
 static void WriteLine(char value);
public static void WriteLine (char value);
static member WriteLine : char -> unit
Public Shared Sub WriteLine (value As Char)

Parâmetros

value
Char

O valor a ser gravado.

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(Boolean)

Grava a representação de texto do valor booliano especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(bool value);
public static void WriteLine (bool value);
static member WriteLine : bool -> unit
Public Shared Sub WriteLine (value As Boolean)

Parâmetros

value
Boolean

O valor a ser gravado.

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir gera dez inteiros aleatórios e usa o Console.WriteLine(Boolean) método para indicar se eles estão mesmo.

using namespace System;

void main()
{
   // Assign 10 random integers to an array.
   Random^ rnd = gcnew Random();
   array<Int32>^ numbers = gcnew array<Int32>(10); 
   for (int ctr = 0; ctr <= numbers->GetUpperBound(0); ctr++)
      numbers[ctr] = rnd->Next();

   // Determine whether the numbers are even or odd.
   for each (Int32 number in numbers) {
      bool even = (number % 2 == 0);
      Console::WriteLine("Is {0} even:", number);
      Console::WriteLine(even);
      Console::WriteLine();      
   }
}
// Assign 10 random integers to an array.
Random rnd = new Random();
int[] numbers = new int[10];
for (int ctr = 0; ctr <= numbers.GetUpperBound(0); ctr++)
   numbers[ctr] = rnd.Next();

// Determine whether the numbers are even or odd.
foreach (var number in numbers) {
   bool even = (number % 2 == 0);
   Console.WriteLine("Is {0} even:", number);
   Console.WriteLine(even);
   Console.WriteLine();
}
// Assign 10 random integers to an array.
let rnd = Random()
let numbers = 
    [ for _ = 0 to 9 do
        rnd.Next()]

// Determine whether the numbers are even or odd.
for number in numbers do
    let even = number % 2 = 0
    Console.WriteLine $"Is {number} even:"
    Console.WriteLine even
    Console.WriteLine()
Module Example
   Public Sub Main()
      ' Assign 10 random integers to an array.
      Dim rnd As New Random()
      Dim numbers(9) As Integer
      For ctr As Integer = 0 To numbers.GetUpperBound(0)
         numbers(ctr) = rnd.Next
      Next
      
      ' Determine whether the numbers are even or odd.
      For Each number In numbers
         Dim even As Boolean = (number mod 2 = 0)
         Console.WriteLine("Is {0} even:", number)
         Console.WriteLine(even)
         Console.WriteLine()      
      Next
   End Sub
End Module

Comentários

A representação de texto value de é produzida chamando o método Boolean.ToString .

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine()

Grava o terminador de linha atual no fluxo de saída padrão.

public:
 static void WriteLine();
public static void WriteLine ();
static member WriteLine : unit -> unit
Public Shared Sub WriteLine ()

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo altera o terminador de linha de seu valor padrão de "\r\n" ou vbCrLf para "\r\n\r\n" ou vbCrLf + vbCrLf . Em seguida, ele chama WriteLine() os métodos e para exibir a saída para o WriteLine(String) console.

using namespace System;

void main()
{
   array<String^>^ lines = gcnew array<String^> { "This is the first line.", 
                                                  "This is the second line." };
   // Output the lines using the default newline sequence.
   Console::WriteLine("With the default new line characters:");
   Console::WriteLine();
   for each (String^ line in lines)
      Console::WriteLine(line);

   Console::WriteLine();

   // Redefine the newline characters to double space.
   Console::Out->NewLine = "\r\n\r\n";
   // Output the lines using the new newline sequence.
   Console::WriteLine("With redefined new line characters:");
   Console::WriteLine();
   for each (String^ line in lines)
      Console::WriteLine(line);
}
// The example displays the following output:
//       With the default new line characters:
//       
//       This is the first line.
//       This is the second line.
//       
//       With redefined new line characters:
//       
//       
//       
//       This is the first line.
//       
//       This is the second line.
string[] lines = { "This is the first line.",
                   "This is the second line." };
// Output the lines using the default newline sequence.
Console.WriteLine("With the default new line characters:");
Console.WriteLine();
foreach (string line in lines)
   Console.WriteLine(line);

Console.WriteLine();

// Redefine the newline characters to double space.
Console.Out.NewLine = "\r\n\r\n";
// Output the lines using the new newline sequence.
Console.WriteLine("With redefined new line characters:");
Console.WriteLine();
foreach (string line in lines)
   Console.WriteLine(line);

// The example displays the following output:
//       With the default new line characters:
//
//       This is the first line.
//       This is the second line.
//
//       With redefined new line characters:
//
//
//
//       This is the first line.
//
//       This is the second line.
let lines = 
    [ "This is the first line."
      "This is the second line." ]
      
// Output the lines using the default newline sequence.
Console.WriteLine "With the default new line characters:"
Console.WriteLine()
for line in lines do
    Console.WriteLine line

Console.WriteLine()

// Redefine the newline characters to double space.
Console.Out.NewLine <- "\r\n\r\n"
// Output the lines using the new newline sequence.
Console.WriteLine "With redefined new line characters:"
Console.WriteLine()
for line in lines do
    Console.WriteLine line

// The example displays the following output:
//       With the default new line characters:
//
//       This is the first line.
//       This is the second line.
//
//       With redefined new line characters:
//
//
//
//       This is the first line.
//
//       This is the second line.
Module Example
   Public Sub Main()
      Dim lines() As String = { "This is the first line.", _
                                "This is the second line." }
      ' Output the lines using the default newline sequence.
      Console.WriteLine("With the default new line characters:")
      Console.WriteLine()
      For Each line As String In lines
         Console.WriteLine(line)
      Next
      Console.WriteLine()
      
      ' Redefine the newline characters to double space.
      Console.Out.NewLine = vbCrLf + vbCrLf
      ' Output the lines using the new newline sequence.
      Console.WriteLine("With redefined new line characters:")
      Console.WriteLine()
      For Each line As String In lines
         Console.WriteLine(line)
      Next
   End Sub
End Module
' The example displays the following output:
'       With the default new line characters:
'       
'       This is the first line.
'       This is the second line.
'       
'       With redefined new line characters:
'       
'       
'       
'       This is the first line.
'       
'       This is the second line.

Comentários

O terminador de linha padrão é uma cadeia de caracteres cujo valor é um retorno de carro seguido por um feed de linha ("\r\n" em C# ou vbCrLf em Visual Basic). Você pode alterar o terminador de linha definindo a TextWriter.NewLine propriedade da propriedade como outra cadeia de Out caracteres. O exemplo fornece uma ilustração.

Confira também

Aplica-se a

WriteLine(String, Object, Object, Object)

Grava a representação de texto dos objetos especificados, seguido de um terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

public:
 static void WriteLine(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2);
public static void WriteLine (string format, object? arg0, object? arg1, object? arg2);
public static void WriteLine (string format, object arg0, object arg1, object arg2);
static member WriteLine : string * obj * obj * obj -> unit
Public Shared Sub WriteLine (format As String, arg0 As Object, arg1 As Object, arg2 As Object)

Parâmetros

format
String

Uma cadeia de caracteres de formato de composição.

arg0
Object

O primeiro objeto a ser gravado usando-se format.

arg1
Object

O segundo objeto a ser gravado usando format.

arg2
Object

O terceiro objeto a ser gravado usando-se format.

Exceções

Ocorreu um erro de E/S.

format é null.

A especificação de formato em format é inválida.

Exemplos

O exemplo a seguir demonstra os especificadores de formatação padrão para números, datas e enumerações.

// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.

using namespace System;

public enum class Color {Yellow = 1, Blue, Green};

int main() 
{
    DateTime thisDate = DateTime::Now;
    Console::Clear();

    // Format a negative integer or floating-point number in various ways.
    Console::WriteLine("Standard Numeric Format Specifiers");
    Console::WriteLine(
        "(C) Currency: . . . . . . . . {0:C}\n" +
        "(D) Decimal:. . . . . . . . . {0:D}\n" +
        "(E) Scientific: . . . . . . . {1:E}\n" +
        "(F) Fixed point:. . . . . . . {1:F}\n" +
        "(G) General:. . . . . . . . . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(N) Number: . . . . . . . . . {0:N}\n" +
        "(P) Percent:. . . . . . . . . {1:P}\n" +
        "(R) Round-trip: . . . . . . . {1:R}\n" +
        "(X) Hexadecimal:. . . . . . . {0:X}\n",
        -123, -123.45f); 

    // Format the current date in various ways.
    Console::WriteLine("Standard DateTime Format Specifiers");
    Console::WriteLine(
        "(d) Short date: . . . . . . . {0:d}\n" +
        "(D) Long date:. . . . . . . . {0:D}\n" +
        "(t) Short time: . . . . . . . {0:t}\n" +
        "(T) Long time:. . . . . . . . {0:T}\n" +
        "(f) Full date/short time: . . {0:f}\n" +
        "(F) Full date/long time:. . . {0:F}\n" +
        "(g) General date/short time:. {0:g}\n" +
        "(G) General date/long time: . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(M) Month:. . . . . . . . . . {0:M}\n" +
        "(R) RFC1123:. . . . . . . . . {0:R}\n" +
        "(s) Sortable: . . . . . . . . {0:s}\n" +
        "(u) Universal sortable: . . . {0:u} (invariant)\n" +
        "(U) Universal full date/time: {0:U}\n" +
        "(Y) Year: . . . . . . . . . . {0:Y}\n", 
        thisDate);

    // Format a Color enumeration value in various ways.
    Console::WriteLine("Standard Enumeration Format Specifiers");
    Console::WriteLine(
        "(G) General:. . . . . . . . . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
        "(D) Decimal number: . . . . . {0:D}\n" +
        "(X) Hexadecimal:. . . . . . . {0:X}\n", 
        Color::Green);       

};


/*
This code example produces the following results:

Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85

Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004

Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003

*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.

using System;
class Sample
{
    enum Color {Yellow = 1, Blue, Green};
    static DateTime thisDate = DateTime.Now;

    public static void Main()
    {
        Console.Clear();

        // Format a negative integer or floating-point number in various ways.
        Console.WriteLine("Standard Numeric Format Specifiers");
        Console.WriteLine(
            "(C) Currency: . . . . . . . . {0:C}\n" +
            "(D) Decimal:. . . . . . . . . {0:D}\n" +
            "(E) Scientific: . . . . . . . {1:E}\n" +
            "(F) Fixed point:. . . . . . . {1:F}\n" +
            "(G) General:. . . . . . . . . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(N) Number: . . . . . . . . . {0:N}\n" +
            "(P) Percent:. . . . . . . . . {1:P}\n" +
            "(R) Round-trip: . . . . . . . {1:R}\n" +
            "(X) Hexadecimal:. . . . . . . {0:X}\n",
            -123, -123.45f);

        // Format the current date in various ways.
        Console.WriteLine("Standard DateTime Format Specifiers");
        Console.WriteLine(
            "(d) Short date: . . . . . . . {0:d}\n" +
            "(D) Long date:. . . . . . . . {0:D}\n" +
            "(t) Short time: . . . . . . . {0:t}\n" +
            "(T) Long time:. . . . . . . . {0:T}\n" +
            "(f) Full date/short time: . . {0:f}\n" +
            "(F) Full date/long time:. . . {0:F}\n" +
            "(g) General date/short time:. {0:g}\n" +
            "(G) General date/long time: . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(M) Month:. . . . . . . . . . {0:M}\n" +
            "(R) RFC1123:. . . . . . . . . {0:R}\n" +
            "(s) Sortable: . . . . . . . . {0:s}\n" +
            "(u) Universal sortable: . . . {0:u} (invariant)\n" +
            "(U) Universal full date/time: {0:U}\n" +
            "(Y) Year: . . . . . . . . . . {0:Y}\n",
            thisDate);

        // Format a Color enumeration value in various ways.
        Console.WriteLine("Standard Enumeration Format Specifiers");
        Console.WriteLine(
            "(G) General:. . . . . . . . . {0:G}\n" +
            "    (default):. . . . . . . . {0} (default = 'G')\n" +
            "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
            "(D) Decimal number: . . . . . {0:D}\n" +
            "(X) Hexadecimal:. . . . . . . {0:X}\n",
            Color.Green);
    }
}
/*
This code example produces the following results:

Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
    (default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85

Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
    (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004

Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
    (default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003

*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.

open System

type Color = 
    | Yellow = 1
    | Blue = 2
    | Green = 3

let thisDate = DateTime.Now

Console.Clear()

// Format a negative integer or floating-point number in various ways.
Console.WriteLine "Standard Numeric Format Specifiers"
Console.WriteLine(
    "(C) Currency: . . . . . . . . {0:C}\n" +
    "(D) Decimal:. . . . . . . . . {0:D}\n" +
    "(E) Scientific: . . . . . . . {1:E}\n" +
    "(F) Fixed point:. . . . . . . {1:F}\n" +
    "(G) General:. . . . . . . . . {0:G}\n" +
    "    (default):. . . . . . . . {0} (default = 'G')\n" +
    "(N) Number: . . . . . . . . . {0:N}\n" +
    "(P) Percent:. . . . . . . . . {1:P}\n" +
    "(R) Round-trip: . . . . . . . {1:R}\n" +
    "(X) Hexadecimal:. . . . . . . {0:X}\n",
    -123, -123.45f)

// Format the current date in various ways.
Console.WriteLine "Standard DateTime Format Specifiers"
Console.WriteLine(
    "(d) Short date: . . . . . . . {0:d}\n" +
    "(D) Long date:. . . . . . . . {0:D}\n" +
    "(t) Short time: . . . . . . . {0:t}\n" +
    "(T) Long time:. . . . . . . . {0:T}\n" +
    "(f) Full date/short time: . . {0:f}\n" +
    "(F) Full date/long time:. . . {0:F}\n" +
    "(g) General date/short time:. {0:g}\n" +
    "(G) General date/long time: . {0:G}\n" +
    "    (default):. . . . . . . . {0} (default = 'G')\n" +
    "(M) Month:. . . . . . . . . . {0:M}\n" +
    "(R) RFC1123:. . . . . . . . . {0:R}\n" +
    "(s) Sortable: . . . . . . . . {0:s}\n" +
    "(u) Universal sortable: . . . {0:u} (invariant)\n" +
    "(U) Universal full date/time: {0:U}\n" +
    "(Y) Year: . . . . . . . . . . {0:Y}\n",
    thisDate)

// Format a Color enumeration value in various ways.
Console.WriteLine "Standard Enumeration Format Specifiers"
Console.WriteLine(
    "(G) General:. . . . . . . . . {0:G}\n" +
    "    (default):. . . . . . . . {0} (default = 'G')\n" +
    "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
    "(D) Decimal number: . . . . . {0:D}\n" +
    "(X) Hexadecimal:. . . . . . . {0:X}\n",
    Color.Green)


// This code example produces the following results:
//
// Standard Numeric Format Specifiers
// (C) Currency: . . . . . . . . ($123.00)
// (D) Decimal:. . . . . . . . . -123
// (E) Scientific: . . . . . . . -1.234500E+002
// (F) Fixed point:. . . . . . . -123.45
// (G) General:. . . . . . . . . -123
//     (default):. . . . . . . . -123 (default = 'G')
// (N) Number: . . . . . . . . . -123.00
// (P) Percent:. . . . . . . . . -12,345.00 %
// (R) Round-trip: . . . . . . . -123.45
// (X) Hexadecimal:. . . . . . . FFFFFF85
//
// Standard DateTime Format Specifiers
// (d) Short date: . . . . . . . 6/26/2004
// (D) Long date:. . . . . . . . Saturday, June 26, 2004
// (t) Short time: . . . . . . . 8:11 PM
// (T) Long time:. . . . . . . . 8:11:04 PM
// (f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
// (F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
// (g) General date/short time:. 6/26/2004 8:11 PM
// (G) General date/long time: . 6/26/2004 8:11:04 PM
//     (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
// (M) Month:. . . . . . . . . . June 26
// (R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
// (s) Sortable: . . . . . . . . 2004-06-26T20:11:04
// (u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
// (U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
// (Y) Year: . . . . . . . . . . June, 2004
//
// Standard Enumeration Format Specifiers
// (G) General:. . . . . . . . . Green
//     (default):. . . . . . . . Green (default = 'G')
// (F) Flags:. . . . . . . . . . Green (flags or integer)
// (D) Decimal number: . . . . . 3
// (X) Hexadecimal:. . . . . . . 00000003
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.

Class Sample
   Public Enum Color
      Yellow = 1
      Blue = 2
      Green = 3
   End Enum 'Color
   Private Shared thisDate As DateTime = DateTime.Now
   
   Public Shared Sub Main()
      Console.Clear()

      ' Format a negative integer or floating-point number in various ways.
      Console.WriteLine("Standard Numeric Format Specifiers")
      Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
                        "(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
                        "(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
                        "(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
                        "(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
                        "(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
                        "(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
                        "(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
                        - 123, - 123.45F)

      ' Format the current date in various ways.
      Console.WriteLine("Standard DateTime Format Specifiers")
      Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
                        "(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
                        "(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
                        "(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
                        "(f) Full date/short time: . . {0:f}" & vbCrLf & _
                        "(F) Full date/long time:. . . {0:F}" & vbCrLf & _
                        "(g) General date/short time:. {0:g}" & vbCrLf & _
                        "(G) General date/long time: . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
                        "(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
                        "(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
                        "(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
                        "(U) Universal full date/time: {0:U}" & vbCrLf & _
                        "(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
                        thisDate)

      ' Format a Color enumeration value in various ways.
      Console.WriteLine("Standard Enumeration Format Specifiers")
      Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
                        "(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
                        "(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
                        Color.Green)
   End Sub
End Class
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
'    (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
'    (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
'    (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003
'

O exemplo a seguir é uma calculadora de gorjetas que calcula uma gorjeta de 18% e usa o método WriteLine para exibir o valor da cobrança original, o valor da gorjeta e o valor total. O exemplo é um aplicativo de console que requer que o usuário forneça o valor da cobrança original como um parâmetro de linha de comando.

using System;

public class TipCalculator
{
    private const double tipRate = 0.18;
    public static void Main(string[] args)
    {
        double billTotal;
        if (args.Length == 0 || ! Double.TryParse(args[0], out billTotal))
        {
            Console.WriteLine("usage: TIPCALC total");
            return;
        }
        double tip = billTotal * tipRate;
        Console.WriteLine();
        Console.WriteLine($"Bill total:\t{billTotal,8:c}");
        Console.WriteLine($"Tip total/rate:\t{tip,8:c} ({tipRate:p1})");
        Console.WriteLine(("").PadRight(24, '-'));
        Console.WriteLine($"Grand total:\t{billTotal + tip,8:c}");
    }
}

/*
>tipcalc 52.23

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

let tipRate = 0.18

let args = Environment.GetCommandLineArgs()[1..] 

if args.Length = 0 then 
    Console.WriteLine "usage: TIPCALC total"
else
    match Double.TryParse args[0] with
    | true, billTotal ->
        let tip = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine $"Bill total:\t{billTotal,8:c}" 
        Console.WriteLine $"Tip total/rate:\t{tip,8:c} ({tipRate:p1})"
        Console.WriteLine("".PadRight(24, '-'))
        Console.WriteLine $"Grand total:\t{billTotal + tip,8:c}" 
    | _ ->
        Console.WriteLine "usage: TIPCALC total"

// >tipcalc 52.23
//
// Bill total:       $52.23
// Tip total/rate:    $9.40 (18.0 %)
// ------------------------
// Grand total:      $61.63
Public Module TipCalculator
    Private Const tipRate As Double = 0.18
   
    Public Sub Main(args As String())
        Dim billTotal As Double
        If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
            Console.WriteLine("usage: TIPCALC total")
            Return
        End If

        Dim tip As Double = billTotal * tipRate
        Console.WriteLine()
        Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
        Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
        Console.WriteLine("".PadRight(24, "-"c))
        Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
    End Sub

End Module

'Example Output:
'---------------
' >tipcalc 52.23
' 
' Bill total:       $52.23
' Tip total/rate:    $9.40 (18.0 %)
' ------------------------
' Grand total:      $61.63

Comentários

Esse método usa o recurso de formatação composta do .NET para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.

O parâmetro format consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.

A sintaxe de um item de formato é { index[ , alignment][ : formatString] , que especifica um índice obrigatório, o comprimento opcional e o alinhamento do texto formatado e uma cadeia de caracteres opcional de caracteres de especificador de formato que regem como o valor do objeto correspondente } é formatado.

O .NET fornece amplo suporte à formatação, que é descrito em mais detalhes nos tópicos de formatação a seguir.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(Object)

Grava a representação de texto do objeto especificado, seguido do terminador de linha atual, no fluxo de saída padrão.

public:
 static void WriteLine(System::Object ^ value);
public static void WriteLine (object? value);
public static void WriteLine (object value);
static member WriteLine : obj -> unit
Public Shared Sub WriteLine (value As Object)

Parâmetros

value
Object

O valor a ser gravado.

Exceções

Ocorreu um erro de E/S.

Exemplos

O exemplo a seguir usa o WriteLine(Object) método para exibir cada valor em uma matriz de objeto para o console.

using namespace System;

void main()
{
   array<Object^>^ values = { true, 12.632, 17908, "stringValue",
                              'a', (Decimal) 16907.32 };
   for each (Object^ value in values)
      Console::WriteLine(value);
}
// The example displays the following output:
//    True
//    12.632
//    17908
//    stringValue
//    a
//    16907.32
Object[] values = { true, 12.632, 17908, "stringValue",
                           'a', 16907.32m };
foreach (var value in values)
   Console.WriteLine(value);

// The example displays the following output:
//    True
//    12.632
//    17908
//    stringValue
//    a
//    16907.32
let values: obj [] = 
    [| true; 12.632; 17908; "stringValue"; 'a'; 16907.32M |]

for value in values do
   Console.WriteLine value

// The example displays the following output:
//    True
//    12.632
//    17908
//    stringValue
//    a
//    16907.32
Module Example
   Public Sub Main()
      Dim values() As Object = { True, 12.632, 17908, "stringValue",
                                 "a"c, 16907.32d }
      For Each value In values
         Console.WriteLine(value)
      Next                           
   End Sub
End Module
' The example displays the following output:
'    True
'    12.632
'    17908
'    stringValue
'    a
'    16907.32

Comentários

Se value for null, o terminador de linha será gravado. Caso contrário, o ToString método de value é chamado para produzir sua representação de cadeia de caracteres e a cadeia de caracteres resultante é gravada no fluxo de saída padrão.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Confira também

Aplica-se a

WriteLine(String, Object, Object, Object, Object)

Importante

Esta API não está em conformidade com CLS.

Grava a representação de texto dos objetos especificados e a lista de parâmetros de tamanho variável, seguido do terminador de linha atual, no fluxo de saída padrão usando as informações de formato especificadas.

public:
 static void WriteLine(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2, System::Object ^ arg3);
[System.CLSCompliant(false)]
public static void WriteLine (string format, object arg0, object arg1, object arg2, object arg3);
[<System.CLSCompliant(false)>]
static member WriteLine : string * obj * obj * obj * obj -> unit
Public Shared Sub WriteLine (format As String, arg0 As Object, arg1 As Object, arg2 As Object, arg3 As Object)

Parâmetros

format
String

Uma cadeia de caracteres de formato de composição.

arg0
Object

O primeiro objeto a ser gravado usando-se format.

arg1
Object

O segundo objeto a ser gravado usando format.

arg2
Object

O terceiro objeto a ser gravado usando-se format.

arg3
Object

O quarto objeto a ser gravado usando format.

Atributos

Exceções

Ocorreu um erro de E/S.

format é null.

A especificação de formato em format é inválida.

Exemplos

O exemplo a seguir ilustra o uso de argumentos de variável com o WriteLine(String, Object, Object, Object, Object) método . O método é chamado com uma cadeia de caracteres de formato composto e cinco itens de formato.

using namespace System;

int CountLetters(String^ value);
int CountWhitespace(String^ value);

void main()
{
   String^ value = "This is a test string.";
   
   
   Console::WriteLine("The string '{0}' consists of:" +
                      "{4}{1} characters{4}{2} letters{4}" +
                      "{3} white-space characters", 
                      value, value->Length, CountLetters(value), 
                      CountWhitespace(value), Environment::NewLine);
}

int CountLetters(String^ value)
{
   int nLetters = 0;
   for each (Char ch in value) {
      if (Char::IsLetter(ch))
         nLetters++;
   }
   return nLetters;
}

int CountWhitespace(String^ value)
{
   int nWhitespace = 0;
   for each (Char ch in value) {
      if (Char::IsWhiteSpace(ch))
         nWhitespace++;
   }
   return nWhitespace;
}
// The example displays the following output:
//    The string 'This is a test string.' consists of:
//    22 characters
//    17 letters
//    4 white-space characters

Comentários

Observação

Esta API não está em conformidade com CLS. A alternativa compatível com CLS é Console.WriteLine(String, Object[]). Os compiladores C# e Visual Basic resolvem automaticamente uma chamada para esse método como uma chamada para Console.WriteLine(String, Object[]) .

Esse método usa o recurso de formatação composta do .NET para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.

O parâmetro format consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.

A sintaxe de um item de formato é { index[ , alignment][ : formatString] , que especifica um índice obrigatório, o comprimento opcional e o alinhamento do texto formatado e uma cadeia de caracteres opcional de caracteres de especificador de formato que regem como o valor do objeto correspondente } é formatado.

O .NET fornece amplo suporte à formatação, que é descrito em mais detalhes nos tópicos de formatação a seguir.

Para obter mais informações sobre o terminador de linha, consulte a seção Comentários do método WriteLine que não usa parâmetros.

Notas aos Chamadores

Esse método é marcado com a vararg palavra-chave , o que significa que ele dá suporte a um número variável de parâmetros. O método pode ser chamado de Visual C++, mas não pode ser chamado do código C# ou Visual Basic código. Os compiladores C# e Visual Basic resolvem chamadas para WriteLine(String, Object, Object, Object, Object) como chamadas para WriteLine(String, Object[]) .

Confira também

Aplica-se a