C# interpolated strings are one of those features people use every day without ever learning the formatting half. The `$"…"` syntax with the `{ }` placeholder is familiar; the bit after the colon — the format specifier — is where the actual power lives. A short tutorial on Code4It walks through the patterns worth keeping in your head.
You already use interpolated strings. This is about making them work harder.
The short version
- An interpolated string uses `$` and `{variable}` to embed values inline.
- Adding `:format` after the variable lets you control how the value is rendered.
- Date formatting supports custom patterns like `yyyy-MM-dd` and named months with `MMMM`.
- Number formatting supports currency (`C`), percentage (`P`), exponential (`E`), and hex (`X`).
- Currency formatting respects the current culture, so the same code prints `$`, `€`, or `¥` depending on the host.
Date formatting that does the work for you
The most useful date tokens are the ones you can rattle off without thinking:
- `dd` — day of the month as a two-digit number.
- `ddd` — abbreviated day name (Mon, Tue, and so on).
- `dddd` — full day name (Monday, Tuesday).
- `hh` — hour on a 12-hour clock (01 to 12).
- `HH` — hour on a 24-hour clock (00 to 23).
- `MMMM` — full month name.
Using `yyyy-MM-dd` after the colon turns a date variable into the form shown in the Code4It example (`2021-05-23`). Swap the specifier to `yyyy-MMMM-dd` and you get a version with the full month name spelled out. Drop the format entirely and the compiler hands you the default culture-aware long form. That default is the trap: it looks fine on your machine and behaves differently on someone else's.
Number formatting that respects the locale
For numbers, the specifiers are even shorter and the results are more dramatic.
- `C` — currency, using the current culture. `$"{cost:C}"` prints `$12.41` in en-US and `£12.41` in en-GB, exactly as in the reference example.
- `E` — exponential notation, useful for scientific output.
- `P` — percentage. `$"{variation:P}"` multiplies the value by a factor of one hundred and adds the locale's percent sign; the Code4It sample turns `-0.254` into `-25.40%`.
- `X` — hexadecimal, useful for low-level and color work.
The currency specifier is the one people underestimate. The exact same interpolated string renders correctly across cultures without any extra code, which is why `C` is usually the right choice over a hard-coded currency symbol.
Our analysis
There is a small but important lesson hiding in the culture-awareness behavior. Interpolation is not just a syntax shortcut — it is a localization vector. If you build a library that prints amounts, defaults matter. Forcing `CultureInfo.InvariantCulture` for logging or data exports and using the current culture for user-facing output is a useful habit to build early.
The other point worth making is that `$"…"` is one tool among several. `string.Format`, `StringBuilder.AppendFormat`, and the newer .NET source generators all handle similar territory. Interpolation wins on readability for most cases, but `string.Format` is still the right answer when the format string itself is data — say, a localized template loaded from a resource file. Same syntax, different trade-offs.
What to watch next: .NET keeps adding format specifiers and culture-aware defaults. The official Microsoft docs on custom date/time format strings and standard numeric format strings are the two pages worth bookmarking.
Worked example: a date-and-currency receipt
Say you are building a small invoice endpoint that prints a one-liner summary. You have a `DateTime issued` and a `decimal total`. One interpolated string does the whole job — a date token followed by a `C` token inside the same braces chain. That prints correctly in en-US and just as correctly in de-DE, with no manual symbol swapping and no culture branching. The format specifier does the heavy lifting; your code stays culture-blind on purpose.
Bottom line
Format specifiers are the part of interpolated strings most developers skip, and they are the part that pays back the fastest. Learn the date tokens you actually use, lean on `C` for currency, and treat culture as a first-class concern.
Key takeaways
- Add `:format` after the variable to control how it renders.
- `C` for currency respects the current culture automatically.
- Always set an explicit date format in logs, exports, and APIs.
Frequently asked questions
Do I have to use `$"…"` to interpolate strings in C#?
No. `string.Format` and `StringBuilder.AppendFormat` cover the same ground. Interpolation is usually the most readable option.
Why does `$"{cost:C}"` print different symbols in different environments?
The `C` specifier uses the current culture's currency settings. Switch the thread's `CultureInfo` to change the output.
Can I format a date to spell out the month name?
Yes. Use `yyyy-MMMM-dd` to render a four-digit year alongside the full month name and a two-digit day.
Is there a format for percentages?
Yes. `P` formats a number as a percentage. The Code4It example shows `0.254` rendered as `-25.40%` in en-US.
Where do I find the full list of format specifiers?
Microsoft's official docs on custom date and time format strings and standard numeric format strings are the canonical references.