Skip to content

Newlines in string interpolations C# 11.0readability

Allow newlines inside interpolated string expression holes.

Prior to C# 11 the expressions inside interpolated string C# 6.0 holes ({ }) had to be on a single line. This could make complex expressions hard to read.

C# 11 removes this restriction and allows the expression inside an interpolation hole to span multiple lines.

Code

C#
var summary = $"Name: {person.FirstName
    + " "
    + person.LastName}";

var filtered = $"Result: {items.Where(i => i.IsActive)
    .Select(i => i.Name)
    .First()}";
C#
var summary = $"Name: {person.FirstName + " " + person.LastName}";

var filtered = $"Result: {items.Where(i => i.IsActive).Select(i => i.Name).First()}";

More information