CKTIS / C#
System.IO.StringReader: practical reference
System.IO.StringReader: practical reference: StringReader exposes an existing string through the TextReader contract.
Version: .NET API; verified on .NET 10.0.14
Syntax
System.IO.StringReader /* select a documented member or constructor */StringReader exposes an existing string through the TextReader contract.
Use it for parsers that expect a TextReader without creating a temporary file.
ReadLine removes the line separator, Dispose ends reader use, and the complete source text already occupies memory.
ReadLine returns null after the end. A trailing line separator terminates the preceding line and does not produce an extra empty line; a leading separator or consecutive separators can produce an empty line.
The complete program actually uses System.IO.StringReader; its exact expected stdout is first.
Examples
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());
Result
first
The complete program actually uses `System.IO.StringReader`; its exact expected stdout is `first`.