String Interpolation vs String.Format

Krythic picture Krythic · Sep 2, 2015 · Viewed 33k times · Source

Is there a noticable performance difference between using string interpolation:

myString += $"{x:x2}";

vs String.Format()?

myString += String.Format("{0:x2}", x);

I am only asking because Resharper is prompting the fix, and I have been fooled before.

Answer

Jeroen Vannevel picture Jeroen Vannevel · Sep 2, 2015

Noticable is relative. However: string interpolation is turned into string.Format() at compile-time so they should end up with the same result.

There are subtle differences though: as we can tell from this question, string concatenation in the format specifier results in an additional string.Concat() call.