Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

Console.WriteLine: praktická referencia

Console.WriteLine: praktická referencia: Console.WriteLine zapíše formátovanú reprezentáciu na aktuálny štandardný výstup a pridá TextWriter.NewLine.

Verzia: .NET API; verified on .NET 10.0.14

Syntax

Console.WriteLine(value)

Console.WriteLine zapíše formátovanú reprezentáciu na aktuálny štandardný výstup a pridá TextWriter.NewLine.

Použite ho na správy konzolového programu a jednoduché výsledky CLI; produkčná diagnostika má použiť štruktúrovaný logger a správny stdout či stderr.

Formátovacie preťaženia používajú composite formatting a aktuálnu kultúru; chybný index vyhodí FormatException a WriteLine neescapuje údaje pre terminál ani protokol.

Presmerovaný Console.Out môže mať iné kódovanie alebo vyhodiť IOException; null v príslušných preťaženiach vypíše prázdnu reprezentáciu pred koncom riadka.

Úplný program skutočne používa Console.WriteLine; presne očakávaný stdout je value=7.

Príklady

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

Console.WriteLine("value={0}", 7);

Výsledok

value=7

Úplný program skutočne používa `Console.WriteLine`; presne očakávaný stdout je `value=7`.

Zdroje