Stats

554 Contributors: 19 Thursday, December 8, 2016
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

String Interpolation

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"

Related Examples