2 hours ago · 7 min read1494 words · Tech · 0 comments

This is the third post in the series: Exploring the .NET 11 preview. Part 1 - Running background tasks in Blazor with Web WorkersPart 2 - .NET (OK, C#) finally gets union types🎉Part 3 - Avoiding ToString() allocations with StringBuilder.MoveChunks (this post) In this post I take a short look at the new StringBuilder.MoveChunks() API introduced in .NET 11 preview 5. First we'll described what the API does and how to use it, then we'll look at how it's implemented. Finally, we'll look at why this API was introduced. Building text efficiently with StringBuilder StringBuilder is a mainstay of almost all .NET applications. You can use StringBuilder to efficiently concatenate strings, characters, and other ToString()ed objects without creating a lot of intermediate strings. Recent versions of .NET added even more efficient rendering with ISpanFormattable implementations. A few years ago I wrote a deep-dive into the implementation of StringBuilder. Things have changed a bit since then, but…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.