Existing answers talk about this as a C # 6 function without the .NET framework component.
This fully applies to nameof , but only to some extent applies to string interpolation.
String interpolation will use string.Format in most cases, but if you are using .NET 4.6, it can also convert the interpolated string to a FormattableString , which is useful if you want invariant formatting:
using System; using System.Globalization; using static System.FormattableString; class Test { static void Main() { CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR"); double d = 0.5; string local = $"{d}"; string invariant = Invariant($"{d}"); Console.WriteLine(local);
Obviously, this will not work if $"{d}" just called string.Format ... instead, in this case, it calls string.Format in the local assignment and calls FormattableStringFactory.Create in the invariant assignment , and calls FormattableString.Invariant on the result. If you try to compile this with an earlier version of the framework, FormattableString will not exist, so it will not compile. You can provide your own implementation of FormattableString and FormattableStringFactory if you really want to, and the compiler will use them accordingly.
source share