Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / C#

System.IO.StringReader: referência prática

System.IO.StringReader: referência prática: StringReader expõe uma string existente através do contrato TextReader.

Versão: .NET API; verified on .NET 10.0.14

Sintaxe

System.IO.StringReader /* select a documented member or constructor */

StringReader expõe uma string existente através do contrato TextReader.

Usa-o para analisadores que esperam TextReader sem criar um ficheiro temporário.

ReadLine remove o separador, Dispose termina o uso e todo o texto de origem já está em memória.

ReadLine devolve null depois do fim. Um separador final termina a linha anterior e não cria uma linha vazia adicional; um separador inicial ou separadores consecutivos podem produzir uma linha vazia.

O programa completo usa realmente System.IO.StringReader; o stdout exato esperado é first.

Exemplos

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;

using var reader = new StringReader("first\nsecond");
Console.WriteLine(reader.ReadLine());

Resultado

first

O programa completo usa realmente `System.IO.StringReader`; o stdout exato esperado é `first`.

Fontes