From 10a7cb366aa9f38d63df68e660e888fb73e12d88 Mon Sep 17 00:00:00 2001 From: Dennis Doomen Date: Wed, 25 Mar 2026 07:10:59 -0700 Subject: [PATCH] Update AV1546 guideline Split from #298. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- _rules/1546.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/_rules/1546.md b/_rules/1546.md index 1903bd53..89483c6b 100644 --- a/_rules/1546.md +++ b/_rules/1546.md @@ -4,7 +4,7 @@ rule_category: maintainability title: Prefer interpolated strings over concatenation or `string.Format`. severity: 1 --- -Since .NET 6, interpolated strings are optimized at compile-time, which inlines constants and reduces memory allocations due to boxing and string copying. +Since .NET 6, interpolated strings are optimized at compile-time, which inlines constants and reduces memory allocations due to boxing and string copying. In .NET 8 and later, interpolated strings are further optimized using `DefaultInterpolatedStringHandler`, making them the fastest option in most scenarios. // GOOD string result = $"Welcome, {firstName} {lastName}!"; @@ -17,3 +17,5 @@ Since .NET 6, interpolated strings are optimized at compile-time, which inlines // BAD string result = string.Concat("Welcome, ", firstName, " ", lastName, "!"); + +For building strings in loops or with many parts, consider using `StringBuilder` or raw string literals (C# 11+) when appropriate.