Skip to content
Justice Tech School

String Interpolation and Formatting

$"..." embeds expressions. Format specifiers go after a colon.

Example
double price = 1234.5;
var now = new DateTime(2026, 3, 15);
Console.WriteLine($"{price:C} {price:N1} {0.256:P0}");
Console.WriteLine($"{now:yyyy-MM-dd} {42,6}|{42,-6}|");

Exercise

Interpolate.

"Hi {name}"

Quiz Test

What does {x:N2} do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.