The new string interpolation style in Visual Studio 2015 is this:
Dim s = $\"Hello {name}\"
But if I use this the code analysis tells me I brea
If you're targeting the .NET Framework 4.6, you can take advantage of the fact that string interpolations are implicitly convertible to FormattableString
:
From Customizing string interpolation in C# 6 by Thomas Levesque
A lesser known aspect of this feature is that an interpolated string can be treated either as a
String
, or as anIFormattable
, depending on the context.
static string Invariant(FormattableString formattable)
{
return formattable.ToString(CultureInfo.InvariantCulture);
}
string text = Invariant($"{p.Name} was born on {p.DateOfBirth:D}");