Breaking up long interpolated strings can impact performance in .NET 6

If you’ve created long strings using string interpolation ($) and hit enter to prevent horizontal scroll Visual Studio will + two interpolated strings together.

In .NET 5 and below this didn’t really matter as string concat via + and $ both delegated to String.Concat(). In NET 6 interpolation works different and is faster and more memory efficient so FYI there is a performance difference.. whether it affects you completely depends on your scenario.

Some example benchmarks below…
Click on the image for a larger view in a new tab.

Leave a Reply

Your email address will not be published. Required fields are marked *