Skip to content

String interpolation of only strings should light-up with string.Concat(params ReadOnlySpan<string>) #74538

@stephentoub

Description

@stephentoub

Currently string interpolation when all of the parts are strings prefers to lower to a string.Concat call when there's a string.Concat overload with the exact same number of string parameters. Beyond that, it falls back to using normal interpolation mechanisms. Now that in .NET 9 there's a string.Concat(params ReadOnlySpan<string>) overload, it'd be nice if string interpolation preferred to use that overload when it's available, when all the parts are strings, and when there isn't a better overload of string.Concat available. This statement is invalidated by the new params span overload, which can support passing in all of the strings without an allocation:

// 4. The string is composed of more than 4 components that are all strings themselves. We can turn this into a single
// call to string.Concat. We prefer the builder over this because the builder can use pooling to avoid new allocations, while this
// call will need to allocate a param array.

cc: @333fred

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions