C# › Fundamentals

How does string interpolation compile, and when should you avoid it?

Advanced

Answer

Interpolated strings usually compile to string.Format (or a DefaultInterpolatedStringHandler on modern .NET). Avoid it in hot logging paths where the message may not be emitted — use structured logging instead.
string s = $"User {id} at {DateTime.UtcNow}";
// logging: prefer logger.LogInformation("User {Id}", id);
Real-world example Structured logs let you query by the Id field later instead of parsing a formatted string.