C# string interpolation and format strings
Short answer
Prefix a string with $ and put expressions in braces: $"Hello, {name}!". It is easier to read than composite formatting with {0} placeholders. [S1][S2]
Console.WriteLine($"{item,-10}{price,8:C}{rate:P0}");
Key points
Cformats currency andP0whole-number percentages. [S1]
Claims
- id: C1 claim: Use the $ character to identify an interpolated string. source: S2 evidence: "Use the $ character to identify a string literal as an interpolated string."
- id: C2 claim: Interpolation is easier to read than composite formatting. source: S2 evidence: "It's easier to read than string composite formatting."
- id: C3 claim: Follow an expression with a colon and a format string to format it. source: S1 evidence: "follow the expression with a colon (:) and a format string"
- id: C4 claim: C and P0 produce currency and whole-number percentages. source: S1 evidence: "The standard format strings C and P0 produce currency and whole-number percentages."
Sources
- [S1] Learn string interpolation - C#. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/string-interpolation . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-04.
- [S2] $ - string interpolation - format string output - C# reference. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn (.NET docs), Learn string interpolation - C#, CC BY 4.0 (dotnet/docs); Microsoft Learn (.NET docs), $ - string interpolation - format string output - C# reference, CC BY 4.0 (dotnet/docs).
Cite this
iinventedlight. 2026. "C# string interpolation and format strings." iinventedlight Library, iil:note:m6k9px5c, version of 2026-11-04. https://iinventedlight.com/library/notes/csharp-string-interpolation/. License: CC-BY-4.0.
@misc{iil_note_m6k9px5c,
author = {{iinventedlight}},
title = {{C\# string interpolation and format strings}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/csharp-string-interpolation/},
note = {Permanent ID iil:note:m6k9px5c. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/csharp-string-interpolation.md.