tags

Roslyn

Customizing string interpolation in C# 6

One of the major new features in C# 6 is string interpolation, which allows you to write things like this: string text = $"{p.Name} was born on {p.DateOfBirth:D}"; A lesser known aspect of this feature is that an interpolated string can be treated either as a String, or as an IFormattable, depending on the context. When it is converted to an IFormattable, it constructs a FormattableString object that implements the interface and exposes: