Console.WriteLine メソッド

定義

指定したデータを標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

オーバーロード

WriteLine(String, Object, Object)

指定した書式情報を使用して、指定したオブジェクトのテキスト表現を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(String)

指定した文字列値を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Char[], Int32, Int32)

指定した Unicode 文字の部分配列を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(String, Object[])

指定した書式情報を使用して、指定したオブジェクト配列のテキスト表現を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(String, Object)

指定した書式情報を使用して、指定したオブジェクトのテキスト表現を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(UInt64)

指定した 64 ビット符号なし整数値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(UInt32)

指定した 32 ビット符号なし整数値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Single)

指定した単精度浮動小数点値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Decimal)

指定した Decimal 値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Int64)

指定した 64 ビット符号付き整数値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Int32)

指定した 32 ビット符号付き整数値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Double)

指定した倍精度浮動小数点値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Char[])

指定した Unicode 文字配列を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Char)

指定した Unicode 文字を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Boolean)

指定した Boolean 値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine()

現在の行終端記号を標準出力ストリームに書き込みます。

WriteLine(String, Object, Object, Object)

指定した書式情報を使用して、指定したオブジェクトのテキスト表現を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

WriteLine(Object)

指定したオブジェクトのテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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

指定した書式情報を使用して、指定したオブジェクトのテキスト表現と可変長パラメーター リストを標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

注釈

既定の行ターミネータは、値がキャリッジ リターンの後に改行 (C# の場合は "\r\n"、または vbCrLf Visual Basic) の文字列です。 行終端記号を変更するには、プロパティのプロパティをTextWriter.NewLineOut別の文字列に設定します。

WriteLine(String, Object, Object)

指定した書式情報を使用して、指定したオブジェクトのテキスト表現を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

format
String

複合書式設定文字列。

arg0
Object

format を使用して書き込む最初のオブジェクト。

arg1
Object

format を使用して書き込む 2 番目のオブジェクト。

例外

I/O エラーが発生しました。

formatnullです。

format の書式指定が正しくありません。

次の例では、数値、日付、および列挙体の標準的な書式指定子を示します。

// 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
'

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

このメソッドは、.NET の 複合書式設定機能を 使用して、オブジェクトの値をテキスト表現に変換し、その表現を文字列に埋め込みます。 結果の文字列が出力ストリームに書き込まれます。

このパラメーターは format 、このメソッドのパラメーター リスト内のオブジェクトに対応する、0 個以上のインデックス付きプレースホルダー (書式項目と呼ばれます) と混合された 0 個以上のテキスト実行で構成されます。 書式設定プロセスは、各書式項目を、対応するオブジェクトの値のテキスト表現に置き換えます。

書式指定項目の構文は {index[,alignment][:formatString]} で、必須のインデックス、書式設定されたテキストの省略可能な長さと配置、および対応するオブジェクトの値の書式設定方法を制御する書式指定子文字の省略可能な文字列を指定します。

.NET では、広範な書式設定のサポートが提供されています。詳細については、次の書式設定に関するトピックで詳しく説明します。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(String)

指定した文字列値を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

value
String

書き込む値。

例外

I/O エラーが発生しました。

この例では、行終端記号を既定値の "\r\n" または vbCrLf "\r\n\r\n" または + vbCrLf``vbCrLf . 次に、コンソールに出力を WriteLine() 表示するメソッドと WriteLine(String) メソッドを呼び出します。

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.

注釈

値が指定されている場合、 null行終端記号のみが標準出力ストリームに書き込まれます。

行終端記号の詳細については、メソッドの「解説」セクションを WriteLine() 参照してください。

こちらもご覧ください

適用対象

WriteLine(Char[], Int32, Int32)

指定した Unicode 文字の部分配列を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

buffer
Char[]

Unicode 文字の配列。

index
Int32

buffer 内の開始位置。

count
Int32

書き込む文字数。

例外

buffernullです。

index または count が 0 未満です。

indexcount の合計が指定する位置は、buffer 内ではありません。

I/O エラーが発生しました。

注釈

このメソッドは、count標準出力ストリームのbuffer位置indexから始まる文字を書き込みます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(String, Object[])

指定した書式情報を使用して、指定したオブジェクト配列のテキスト表現を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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())

パラメーター

format
String

複合書式設定文字列。

arg
Object[]

format を使用して書き込むオブジェクトの配列。

例外

I/O エラーが発生しました。

format または argnull です。

format の書式指定が正しくありません。

次の例では、数値、日付、および列挙体の標準的な書式指定子を示します。

// 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
'

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

このメソッドは、.NET の 複合書式設定機能を 使用して、オブジェクトの値をテキスト表現に変換し、その表現を文字列に埋め込みます。 結果の文字列が出力ストリームに書き込まれます。

このパラメーターは format 、このメソッドのパラメーター リスト内のオブジェクトに対応する、0 個以上のインデックス付きプレースホルダー (書式項目と呼ばれます) と混合された 0 個以上のテキスト実行で構成されます。 書式設定プロセスは、各書式項目を、対応するオブジェクトの値のテキスト表現に置き換えます。

書式指定項目の構文は {index[,alignment][:formatString]} で、必須のインデックス、書式設定されたテキストの省略可能な長さと配置、および対応するオブジェクトの値の書式設定方法を制御する書式指定子文字の省略可能な文字列を指定します。

.NET では、広範な書式設定のサポートが提供されています。詳細については、次の書式設定に関するトピックで詳しく説明します。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

注意 (呼び出し元)

このメソッドは C++ コードでは呼び出されません。 C++ コンパイラは、文字列と 4 つ以上のオブジェクト パラメーターのリストを呼び出しとして含む System.Console.WriteLine の呼び出しを WriteLine(String, Object, Object, Object, Object)解決します。 これは、文字列とオブジェクト配列を呼び出しとして含む System.Console.WriteLine の呼び出しを解決します WriteLine(String, Object)

こちらもご覧ください

適用対象

WriteLine(String, Object)

指定した書式情報を使用して、指定したオブジェクトのテキスト表現を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

format
String

複合書式設定文字列。

arg0
Object

format を使用して書き込むオブジェクト。

例外

I/O エラーが発生しました。

formatnullです。

format の書式指定が正しくありません。

次の例では、メソッドを WriteLine(String, Object) 呼び出して、ランダムに生成された Boolean 5 つの値を表示します。

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

次の例では、メソッドを WriteLine(String, Object) 呼び出して現在の日付を表示します。 引数の format 書式指定項目では、"D" 標準の日付と時刻の書式指定文字列 を使用して、現在のカルチャの長い日付形式で日付が表示されることに注意してください。

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

注釈

このメソッドは、.NET の 複合書式設定機能を 使用して、オブジェクトの値をテキスト表現に変換し、その表現を文字列に埋め込みます。 結果の文字列が出力ストリームに書き込まれます。

このパラメーターは format 、このメソッドのパラメーター リスト内のオブジェクトに対応する、0 個以上のインデックス付きプレースホルダー (書式項目と呼ばれます) と混合された 0 個以上のテキスト実行で構成されます。 書式設定プロセスは、各書式項目を、対応するオブジェクトの値のテキスト表現に置き換えます。

書式指定項目の構文は {index[,alignment][:formatString]} で、必須のインデックス、書式設定されたテキストの省略可能な長さと配置、および対応するオブジェクトの値の書式設定方法を制御する書式指定子文字の省略可能な文字列を指定します。

.NET では、広範な書式設定のサポートが提供されています。詳細については、次の書式設定に関するトピックで詳しく説明します。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(UInt64)

重要

この API は CLS 準拠ではありません。

指定した 64 ビット符号なし整数値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

value
UInt64

書き込む値。

属性

例外

I/O エラーが発生しました。

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

テキスト表現は、メソッドを value 呼び出 UInt64.ToString すことによって生成されます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(UInt32)

重要

この API は CLS 準拠ではありません。

指定した 32 ビット符号なし整数値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

value
UInt32

書き込む値。

属性

例外

I/O エラーが発生しました。

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

テキスト表現は、メソッドを value 呼び出 UInt32.ToString すことによって生成されます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(Single)

指定した単精度浮動小数点値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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

パラメーター

value
Single

書き込む値。

例外

I/O エラーが発生しました。

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

テキスト表現は、メソッドを value 呼び出 Single.ToString すことによって生成されます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(Decimal)

指定した Decimal 値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

value
Decimal

書き込む値。

例外

I/O エラーが発生しました。

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

テキスト表現は、メソッドを value 呼び出 Decimal.ToString すことによって生成されます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(Int64)

指定した 64 ビット符号付き整数値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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

パラメーター

value
Int64

書き込む値。

例外

I/O エラーが発生しました。

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

テキスト表現は、メソッドを value 呼び出 Int64.ToString すことによって生成されます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(Int32)

指定した 32 ビット符号付き整数値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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

パラメーター

value
Int32

書き込む値。

例外

I/O エラーが発生しました。

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

テキスト表現は、メソッドを value 呼び出 Int32.ToString すことによって生成されます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(Double)

指定した倍精度浮動小数点値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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

パラメーター

value
Double

書き込む値。

例外

I/O エラーが発生しました。

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

テキスト表現は、メソッドを value 呼び出 Double.ToString すことによって生成されます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(Char[])

指定した Unicode 文字配列を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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())

パラメーター

buffer
Char[]

Unicode 文字配列。

例外

I/O エラーが発生しました。

注釈

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(Char)

指定した Unicode 文字を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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

パラメーター

value
Char

書き込む値。

例外

I/O エラーが発生しました。

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(Boolean)

指定した Boolean 値のテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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

パラメーター

value
Boolean

書き込む値。

例外

I/O エラーが発生しました。

次の例では、10 個のランダムな整数を生成し、このメソッドを Console.WriteLine(Boolean) 使用して、整数が偶数かどうかを示します。

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

注釈

テキスト表現は、メソッドを value 呼び出 Boolean.ToString すことによって生成されます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine()

現在の行終端記号を標準出力ストリームに書き込みます。

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

例外

I/O エラーが発生しました。

この例では、行終端記号を既定値の "\r\n" または vbCrLf "\r\n\r\n" または + vbCrLf``vbCrLf . 次に、コンソールに出力を WriteLine() 表示するメソッドと WriteLine(String) メソッドを呼び出します。

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.

注釈

既定の行ターミネータは、値がキャリッジ リターンの後に改行 (C# の場合は "\r\n"、または vbCrLf Visual Basic) の文字列です。 行終端記号を変更するには、プロパティのプロパティをTextWriter.NewLineOut別の文字列に設定します。 具体的な例を次に示します。

こちらもご覧ください

適用対象

WriteLine(String, Object, Object, Object)

指定した書式情報を使用して、指定したオブジェクトのテキスト表現を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

format
String

複合書式設定文字列。

arg0
Object

format を使用して書き込む最初のオブジェクト。

arg1
Object

format を使用して書き込む 2 番目のオブジェクト。

arg2
Object

format を使用して書き込む 3 番目のオブジェクト。

例外

I/O エラーが発生しました。

formatnullです。

format の書式指定が正しくありません。

次の例では、数値、日付、および列挙体の標準的な書式指定子を示します。

// 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
'

次の例は、18% のチップを計算し、元の料金の金額、チップの金額、合計金額を表示する方法を使用 WriteLine するチップ計算ツールです。 この例は、ユーザーが元の料金の金額をコマンド ライン パラメーターとして指定する必要があるコンソール アプリケーションです。

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

注釈

このメソッドは、.NET の 複合書式設定機能を 使用して、オブジェクトの値をテキスト表現に変換し、その表現を文字列に埋め込みます。 結果の文字列が出力ストリームに書き込まれます。

このパラメーターは format 、このメソッドのパラメーター リスト内のオブジェクトに対応する、0 個以上のインデックス付きプレースホルダー (書式項目と呼ばれます) と混合された 0 個以上のテキスト実行で構成されます。 書式設定プロセスは、各書式項目を、対応するオブジェクトの値のテキスト表現に置き換えます。

書式指定項目の構文は {index[,alignment][:formatString]} で、必須のインデックス、書式設定されたテキストの省略可能な長さと配置、および対応するオブジェクトの値の書式設定方法を制御する書式指定子文字の省略可能な文字列を指定します。

.NET では、広範な書式設定のサポートが提供されています。詳細については、次の書式設定に関するトピックで詳しく説明します。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

WriteLine(Object)

指定したオブジェクトのテキスト形式を標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

value
Object

書き込む値。

例外

I/O エラーが発生しました。

次の例では、メソッドを WriteLine(Object) 使用して、オブジェクト配列の各値をコンソールに表示します。

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

注釈

valuenull の場合は、行終端記号だけを書き込みます。 それ以外のToString``value場合は、メソッドが呼び出されて文字列表現が生成され、結果の文字列が標準出力ストリームに書き込まれます。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

こちらもご覧ください

適用対象

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

重要

この API は CLS 準拠ではありません。

指定した書式情報を使用して、指定したオブジェクトのテキスト表現と可変長パラメーター リストを標準出力ストリームに書き込み、続けて現在の行終端記号を書き込みます。

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)

パラメーター

format
String

複合書式設定文字列。

arg0
Object

format を使用して書き込む最初のオブジェクト。

arg1
Object

format を使用して書き込む 2 番目のオブジェクト。

arg2
Object

format を使用して書き込む 3 番目のオブジェクト。

arg3
Object

format を使用して書き込む 4 番目のオブジェクト。

属性

例外

I/O エラーが発生しました。

formatnullです。

format の書式指定が正しくありません。

次の例は、メソッドでの変数引数の使用を WriteLine(String, Object, Object, Object, Object) 示しています。 このメソッドは、複合書式指定文字列と 5 つの書式指定項目を使用して呼び出されます。

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

注釈

注意

この API は、CLS に準拠していません。 CLS 準拠の代わりとして Console.WriteLine(String, Object[]) を使用できます。 C# および Visual Basic コンパイラは、このメソッドの呼び出しを呼び出しとして自動的にConsole.WriteLine(String, Object[])解決します。

このメソッドは、.NET の 複合書式設定機能を 使用して、オブジェクトの値をテキスト表現に変換し、その表現を文字列に埋め込みます。 結果の文字列が出力ストリームに書き込まれます。

このパラメーターは format 、このメソッドのパラメーター リスト内のオブジェクトに対応する、0 個以上のインデックス付きプレースホルダー (書式項目と呼ばれます) と混合された 0 個以上のテキスト実行で構成されます。 書式設定プロセスは、各書式項目を、対応するオブジェクトの値のテキスト表現に置き換えます。

書式指定項目の構文は {index[,alignment][:formatString]} で、必須のインデックス、書式設定されたテキストの省略可能な長さと配置、および対応するオブジェクトの値の書式設定方法を制御する書式指定子文字の省略可能な文字列を指定します。

.NET では、広範な書式設定のサポートが提供されています。詳細については、次の書式設定に関するトピックで詳しく説明します。

行終端記号の詳細については、パラメーターを受け取らないメソッドの「解説」セクションを WriteLine 参照してください。

注意 (呼び出し元)

このメソッドはキーワードで vararg マークされています。これは、可変数のパラメーターをサポートすることを意味します。 このメソッドは Visual C++ から呼び出すことができますが、C# またはVisual Basic コードから呼び出すことはできません。 C# および Visual Basic コンパイラは、呼び出しをWriteLine(String, Object, Object, Object, Object)呼び出WriteLine(String, Object[])しとして解決します。

こちらもご覧ください

適用対象