영어로 읽기

다음을 통해 공유


Console.WriteLine 메서드

정의

지정된 데이터와 현재 줄 종결자를 표준 출력 스트림에 씁니다.

오버로드

WriteLine(String, Object, Object)

지정된 형식 정보를 사용하여 지정된 개체의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(String)

지정된 문자열 값과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(Char[], Int32, Int32)

유니코드 문자의 지정된 하위 배열과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(String, ReadOnlySpan<Object>)

지정된 형식 정보를 사용하여 지정된 개체 범위의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(String, Object[])

지정된 형식 정보를 사용하여 지정된 개체 배열의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(String, Object)

지정된 형식 정보를 사용하여 지정된 개체의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(UInt64)

지정된 64비트 부호 없는 정수 값과 현재 줄 종결자의 텍스트 표현을 표준 출력 스트림에 씁니다.

WriteLine(UInt32)

지정된 32비트 부호 없는 정수 값과 현재 줄 종결자의 텍스트 표현을 표준 출력 스트림에 씁니다.

WriteLine(Single)

지정된 단정밀도 부동 소수점 값의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(Double)

지정된 배정밀도 부동 소수점 값의 텍스트 표현과 현재 줄 종결자 뒤에 표준 출력 스트림을 씁니다.

WriteLine(Int64)

지정된 64비트 부호 있는 정수 값과 현재 줄 종결자의 텍스트 표현을 표준 출력 스트림에 씁니다.

WriteLine(Int32)

지정된 32비트 부호 있는 정수 값과 현재 줄 종결자의 텍스트 표현을 표준 출력 스트림에 씁니다.

WriteLine(Decimal)

지정된 Decimal 값의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(Char[])

지정된 유니코드 문자 배열과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(Char)

지정된 유니코드 문자와 현재 줄 종결자, 값을 표준 출력 스트림에 씁니다.

WriteLine(Boolean)

지정된 부울 값의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine()

현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(String, Object, Object, Object)

지정된 형식 정보를 사용하여 지정된 개체의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

WriteLine(Object)

지정된 개체의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

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

지정된 형식 정보를 사용하여 지정된 개체 및 가변 길이 매개 변수 목록의 텍스트 표현과 현재 줄 종결자 뒤에 표준 출력 스트림을 씁니다.

설명

기본 줄 종결자는 값이 캐리지 리턴 뒤에 줄 바꿈("\r\n" C#, 또는 Visual Basic의 vbCrLf)인 문자열입니다. Out 속성의 TextWriter.NewLine 속성을 다른 문자열로 설정하여 줄 종결자를 변경할 수 있습니다.

WriteLine(String, Object, Object)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 형식 정보를 사용하여 지정된 개체의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (string format, object? arg0, object? arg1);
public static void WriteLine (string format, object arg0, object arg1);

매개 변수

format
String

복합 형식 문자열입니다.

arg0
Object

format사용하여 쓸 첫 번째 개체입니다.

arg1
Object

format사용하여 쓸 두 번째 개체입니다.

예외

I/O 오류가 발생했습니다.

format null.

format 형식 사양이 잘못되었습니다.

예제

다음 예제에서는 숫자, 날짜 및 열거형에 대한 표준 서식 지정 지정자를 보여 줍니다.

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

*/

다음 예제는 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
*/

설명

이 메서드는 .NET의 복합 서식 기능 사용하여 개체 값을 텍스트 표현으로 변환하고 문자열에 해당 표현을 포함합니다. 결과 문자열은 출력 스트림에 기록됩니다.

format 매개 변수는 이 메서드의 매개 변수 목록에 있는 개체에 해당하는 형식 항목이라고 하는 0개 이상의 인덱싱된 자리 표시자와 섞인 텍스트의 0개 이상의 실행으로 구성됩니다. 서식 지정 프로세스는 각 서식 항목을 해당 개체 값의 텍스트 표현으로 바꿉니다.

서식 항목의 구문은 {인덱스[,맞춤][:formatString] ]}.

.NET은 다음 서식 항목에서 자세히 설명하는 광범위한 서식 지정 지원을 제공합니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(String)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 문자열 값과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (string? value);
public static void WriteLine (string value);

매개 변수

value
String

쓸 값입니다.

예외

I/O 오류가 발생했습니다.

예제

이 예제에서는 줄 종결자를 기본값인 "\r\n" 또는 vbCrLf "\r\n\r\n" 또는 vbCrLf + vbCrLf변경합니다. 그런 다음 WriteLine()WriteLine(String) 메서드를 호출하여 출력을 콘솔에 표시합니다.

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.

설명

값이 null경우 줄 종결자만 표준 출력 스트림에 기록됩니다.

줄 종결자에 대한 자세한 내용은 WriteLine() 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Char[], Int32, Int32)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

유니코드 문자의 지정된 하위 배열과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (char[] buffer, int index, int count);

매개 변수

buffer
Char[]

유니코드 문자의 배열입니다.

index
Int32

buffer시작 위치입니다.

count
Int32

쓸 문자 수입니다.

예외

buffer null.

index 또는 count 0보다 작습니다.

index 더하기 countbuffer내에 있지 않은 위치를 지정합니다.

I/O 오류가 발생했습니다.

설명

이 메서드는 표준 출력 스트림에 buffer 위치 index 시작하는 count 문자를 씁니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(String, ReadOnlySpan<Object>)

지정된 형식 정보를 사용하여 지정된 개체 범위의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (string format, scoped ReadOnlySpan<object?> arg);

매개 변수

format
String

복합 형식 문자열입니다.

arg
ReadOnlySpan<Object>

형식을 사용하여 쓸 개체의 범위입니다.

적용 대상

.NET 9
제품 버전
.NET 9

WriteLine(String, Object[])

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 형식 정보를 사용하여 지정된 개체 배열의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (string format, params object?[]? arg);
public static void WriteLine (string format, params object[] arg);

매개 변수

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

*/

다음 예제는 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
*/

설명

이 메서드는 .NET의 복합 서식 기능 사용하여 개체 값을 텍스트 표현으로 변환하고 문자열에 해당 표현을 포함합니다. 결과 문자열은 출력 스트림에 기록됩니다.

format 매개 변수는 이 메서드의 매개 변수 목록에 있는 개체에 해당하는 형식 항목이라고 하는 0개 이상의 인덱싱된 자리 표시자와 섞인 텍스트의 0개 이상의 실행으로 구성됩니다. 서식 지정 프로세스는 각 서식 항목을 해당 개체 값의 텍스트 표현으로 바꿉니다.

서식 항목의 구문은 {인덱스[,맞춤][:formatString] ]}.

.NET은 다음 서식 항목에서 자세히 설명하는 광범위한 서식 지정 지원을 제공합니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

호출자 참고

이 메서드는 C++ 코드에서 호출되지 않습니다. C++ 컴파일러는 문자열과 4개 이상의 개체 매개 변수 목록을 포함하는 System.Console.WriteLine 대한 호출을 WriteLine(String, Object, Object, Object, Object)호출로 확인합니다. 문자열 및 개체 배열을 WriteLine(String, Object)호출로 포함하는 System.Console.WriteLine 호출을 확인합니다.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(String, Object)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 형식 정보를 사용하여 지정된 개체의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (string format, object? arg0);
public static void WriteLine (string format, object arg0);

매개 변수

format
String

복합 형식 문자열입니다.

arg0
Object

format사용하여 쓸 개체입니다.

예외

I/O 오류가 발생했습니다.

format null.

format 형식 사양이 잘못되었습니다.

예제

다음 예제에서는 WriteLine(String, Object) 메서드를 호출하여 임의로 생성된 5개의 Boolean 값을 표시합니다.

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

// The example displays an output similar to the following:
//       True or False: False
//       True or False: True
//       True or False: False
//       True or False: False
//       True or False: True

다음 예제에서는 WriteLine(String, Object) 메서드를 호출하여 현재 날짜를 표시합니다. 인수의 서식 항목은 표준 날짜 및 시간 서식 문자열 "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

설명

이 메서드는 .NET의 복합 서식 기능 사용하여 개체 값을 텍스트 표현으로 변환하고 문자열에 해당 표현을 포함합니다. 결과 문자열은 출력 스트림에 기록됩니다.

format 매개 변수는 이 메서드의 매개 변수 목록에 있는 개체에 해당하는 형식 항목이라고 하는 0개 이상의 인덱싱된 자리 표시자와 섞인 텍스트의 0개 이상의 실행으로 구성됩니다. 서식 지정 프로세스는 각 서식 항목을 해당 개체 값의 텍스트 표현으로 바꿉니다.

서식 항목의 구문은 {인덱스[,맞춤][:formatString] ]}.

.NET은 다음 서식 항목에서 자세히 설명하는 광범위한 서식 지정 지원을 제공합니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(UInt64)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

중요

이 API는 CLS 규격이 아닙니다.

지정된 64비트 부호 없는 정수 값과 현재 줄 종결자의 텍스트 표현을 표준 출력 스트림에 씁니다.

[System.CLSCompliant(false)]
public static void WriteLine (ulong value);

매개 변수

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

설명

value 텍스트 표현은 UInt64.ToString 메서드를 호출하여 생성됩니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(UInt32)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

중요

이 API는 CLS 규격이 아닙니다.

지정된 32비트 부호 없는 정수 값과 현재 줄 종결자의 텍스트 표현을 표준 출력 스트림에 씁니다.

[System.CLSCompliant(false)]
public static void WriteLine (uint value);

매개 변수

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

설명

value 텍스트 표현은 UInt32.ToString 메서드를 호출하여 생성됩니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Single)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 단정밀도 부동 소수점 값의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (float value);

매개 변수

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

설명

value 텍스트 표현은 Single.ToString 메서드를 호출하여 생성됩니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Double)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 배정밀도 부동 소수점 값의 텍스트 표현과 현재 줄 종결자 뒤에 표준 출력 스트림을 씁니다.

public static void WriteLine (double value);

매개 변수

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

설명

value 텍스트 표현은 Double.ToString 메서드를 호출하여 생성됩니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Int64)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 64비트 부호 있는 정수 값과 현재 줄 종결자의 텍스트 표현을 표준 출력 스트림에 씁니다.

public static void WriteLine (long value);

매개 변수

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

설명

value 텍스트 표현은 Int64.ToString 메서드를 호출하여 생성됩니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Int32)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 32비트 부호 있는 정수 값과 현재 줄 종결자의 텍스트 표현을 표준 출력 스트림에 씁니다.

public static void WriteLine (int value);

매개 변수

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

설명

value 텍스트 표현은 Int32.ToString 메서드를 호출하여 생성됩니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Decimal)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 Decimal 값의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (decimal value);

매개 변수

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

설명

value 텍스트 표현은 Decimal.ToString 메서드를 호출하여 생성됩니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Char[])

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 유니코드 문자 배열과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (char[]? buffer);
public static void WriteLine (char[] buffer);

매개 변수

buffer
Char[]

유니코드 문자 배열입니다.

예외

I/O 오류가 발생했습니다.

설명

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Char)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 유니코드 문자와 현재 줄 종결자, 값을 표준 출력 스트림에 씁니다.

public static void WriteLine (char value);

매개 변수

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

설명

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Boolean)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 부울 값의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (bool value);

매개 변수

value
Boolean

쓸 값입니다.

예외

I/O 오류가 발생했습니다.

예제

다음 예제에서는 10개의 임의 정수를 생성하고 Console.WriteLine(Boolean) 메서드를 사용하여 짝수인지 여부를 나타냅니다.

// 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();
}

설명

value 텍스트 표현은 Boolean.ToString 메서드를 호출하여 생성됩니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine()

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine ();

예외

I/O 오류가 발생했습니다.

예제

이 예제에서는 줄 종결자를 기본값인 "\r\n" 또는 vbCrLf "\r\n\r\n" 또는 vbCrLf + vbCrLf변경합니다. 그런 다음 WriteLine()WriteLine(String) 메서드를 호출하여 출력을 콘솔에 표시합니다.

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.

설명

기본 줄 종결자는 값이 캐리지 리턴 뒤에 줄 바꿈("\r\n" C#, 또는 Visual Basic의 vbCrLf)인 문자열입니다. Out 속성의 TextWriter.NewLine 속성을 다른 문자열로 설정하여 줄 종결자를 변경할 수 있습니다. 이 예제에서는 그림을 제공합니다.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(String, Object, Object, Object)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 형식 정보를 사용하여 지정된 개체의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (string format, object? arg0, object? arg1, object? arg2);
public static void WriteLine (string format, object arg0, object arg1, object arg2);

매개 변수

format
String

복합 형식 문자열입니다.

arg0
Object

format사용하여 쓸 첫 번째 개체입니다.

arg1
Object

format사용하여 쓸 두 번째 개체입니다.

arg2
Object

format사용하여 쓸 세 번째 개체입니다.

예외

I/O 오류가 발생했습니다.

format null.

format 형식 사양이 잘못되었습니다.

예제

다음 예제에서는 숫자, 날짜 및 열거형에 대한 표준 서식 지정 지정자를 보여 줍니다.

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

*/

다음 예제는 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
*/

설명

이 메서드는 .NET의 복합 서식 기능 사용하여 개체 값을 텍스트 표현으로 변환하고 문자열에 해당 표현을 포함합니다. 결과 문자열은 출력 스트림에 기록됩니다.

format 매개 변수는 이 메서드의 매개 변수 목록에 있는 개체에 해당하는 형식 항목이라고 하는 0개 이상의 인덱싱된 자리 표시자와 섞인 텍스트의 0개 이상의 실행으로 구성됩니다. 서식 지정 프로세스는 각 서식 항목을 해당 개체 값의 텍스트 표현으로 바꿉니다.

서식 항목의 구문은 {인덱스[,맞춤][:formatString] ]}.

.NET은 다음 서식 항목에서 자세히 설명하는 광범위한 서식 지정 지원을 제공합니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

WriteLine(Object)

Source:
Console.cs
Source:
Console.cs
Source:
Console.cs

지정된 개체의 텍스트 표현과 현재 줄 종결자를 표준 출력 스트림에 씁니다.

public static void WriteLine (object? value);
public static void WriteLine (object value);

매개 변수

value
Object

쓸 값입니다.

예외

I/O 오류가 발생했습니다.

예제

다음 예제에서는 WriteLine(Object) 메서드를 사용하여 개체 배열의 각 값을 콘솔에 표시합니다.

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

설명

value null경우 줄 종결자만 기록됩니다. 그렇지 않으면 문자열 표현을 생성하기 위해 valueToString 메서드가 호출되고 결과 문자열이 표준 출력 스트림에 기록됩니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

추가 정보

적용 대상

.NET 9 및 기타 버전
제품 버전
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

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

중요

이 API는 CLS 규격이 아닙니다.

지정된 형식 정보를 사용하여 지정된 개체 및 가변 길이 매개 변수 목록의 텍스트 표현과 현재 줄 종결자 뒤에 표준 출력 스트림을 씁니다.

[System.CLSCompliant(false)]
public static void WriteLine (string format, object arg0, object arg1, object arg2, object arg3);

매개 변수

format
String

복합 형식 문자열입니다.

arg0
Object

format사용하여 쓸 첫 번째 개체입니다.

arg1
Object

format사용하여 쓸 두 번째 개체입니다.

arg2
Object

format사용하여 쓸 세 번째 개체입니다.

arg3
Object

format사용하여 쓸 네 번째 개체입니다.

특성

예외

I/O 오류가 발생했습니다.

format null.

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개 이상의 실행으로 구성됩니다. 서식 지정 프로세스는 각 서식 항목을 해당 개체 값의 텍스트 표현으로 바꿉니다.

서식 항목의 구문은 {인덱스[,맞춤][:formatString] ]}.

.NET은 다음 서식 항목에서 자세히 설명하는 광범위한 서식 지정 지원을 제공합니다.

줄 종결자에 대한 자세한 내용은 매개 변수를 사용하지 않는 WriteLine 메서드의 설명 섹션을 참조하세요.

호출자 참고

이 메서드는 vararg 키워드로 표시됩니다. 즉, 변수 수의 매개 변수를 지원합니다. 이 메서드는 Visual C++에서 호출할 수 있지만 C# 또는 Visual Basic 코드에서는 호출할 수 없습니다. C# 및 Visual Basic 컴파일러는 WriteLine(String, Object, Object, Object, Object) 호출을 WriteLine(String, Object[])호출로 확인합니다.

추가 정보

적용 대상

.NET Framework 4.8.1 및 기타 버전
제품 버전
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1