ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Pass string interpolation expression

Last modified: 08 April 2024

One of the biggest downsides of the string interpolation expression feature introduced in C# 6.0 was the inability to efficiently delay string formatting and delegate it to the consumer of the interpolated string expression. This is important in logging frameworks that allow changing the logging level at runtime, where you don't want to waste resources on frequent logging invocations when logging is disabled:

C# 10 fixes this problem by introducing the concept of interpolated string handlers. For the end-user, this means that a string interpolation expression generally works faster in .NET 6 and allows usage of Span<char> values in interpolation holes. For library authors, this feature allows controlling whether the string interpolation expression is converted to string or not.

ReSharper recognizes the "interpolated string handlers' pattern in library code and suggests using string interpolation expressions where possible: