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
This modified text is an extract of the original Stack Overflow Documentation created by following
contributors and released under
CC BY-SA 3.0