CKTIS / C#
System.IO.StringWriter: practical reference
System.IO.StringWriter: practical reference: StringWriter accumulates text in a StringBuilder through the TextWriter contract.
Version: .NET API; verified on .NET 10.0.14
Syntax
System.IO.StringWriter /* select a documented member or constructor */StringWriter accumulates text in a StringBuilder through the TextWriter contract.
Use it for formatters and serializers that write to TextWriter when the final result must be a string.
Formatting follows the supplied culture, and a large result grows in memory before ToString returns it all.
NewLine is configurable, and writing after Dispose throws ObjectDisposedException.
The complete program actually uses System.IO.StringWriter; its exact expected stdout is value=7.
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 writer = new StringWriter(CultureInfo.InvariantCulture);
writer.Write("value={0}", 7);
Console.WriteLine(writer.ToString());
Result
value=7
The complete program actually uses `System.IO.StringWriter`; its exact expected stdout is `value=7`.