Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
Krzysztof Cwalina edited this page Jan 20, 2015 · 24 revisions

#System.Text.Formatting System.Text.Formatting APIs are similar to the existing StringBuilder and TextWriter APIs. They are designed to format values into text streams and to build complex strings. But these APIs are optimized for creating text for the Web. They do formatting with minimum GC heap allocations (1/6 of allocations in some scenarios) and can format directly to UTF8 streams. This can result in significant performance wins for software that does a lot of text

#Hello World

var formatter = new StringFormatter();
formatter.Append(100); // String.ToString() is not called here, or ever
string text = formatter.ToString();

#Hello World

Stream stream = new MemoryStream(256);
var writer = new StreamFormatter(stream, FormattingData.InvariantUtf8);
writer.Append(100); // this writes UTF8 to the stream without creating UTF16 first
Clone this wiki locally