C# Language String Interpolation

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • $"content {expression} content"
  • $"content {expression:format} content"
  • $"content {expression} {{content in braces}} content}"
  • $"content {expression:format} {{content in braces}} content}"

Remarks

String interpolation is a shorthand for the string.Format() method that makes it easier to build strings with variable and expression values inside of them.

var name = "World";
var oldWay = string.Format("Hello, {0}!", name);  // returns "Hello, World"
var newWay = $"Hello, {name}!";                   // returns "Hello, World"


Got any C# Language Question?