capypad
0 day streak
csharp / beginner
Snippet

String Interpolation

String interpolation uses the '$' character to allow variables to be inserted directly into a string inside curly braces, making the code much more readable.

snippet.csharp
csharp
1
2
3
string tool = "C#";
int version = 12;
Console.WriteLine($"Learning {tool} version {version} is fun!");
Breakdown
1
$"..."
The dollar sign indicates that the string supports interpolation.
2
{tool}
Variables inside curly braces are replaced by their actual values at runtime.