Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Output · Lesson 18 of 27

String Interpolation

A free lesson from Swipe Coding · C#, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
One little dollar sign unlocks a much cleaner way to build text. 💲

C# has a very convenient feature called "string interpolation". By placing a $ symbol right before the opening quotation mark, you can drop curly braces { } directly into your text, and whatever is inside them gets calculated and inserted into the output automatically.

Console.WriteLine($"5 plus 3 is {5 + 3}");

// Output:
// 5 plus 3 is 8
The expression inside { } is evaluated first, and the result is inserted right into the text.

You are not limited to math — you can put almost any expression inside the curly braces, and C# will convert the result to text for you automatically. Soon, once you learn about variables, you will use interpolation constantly to weave their values straight into your output.

Console.WriteLine($"Today is day {1}, and tomorrow is day {1 + 1}.");

// Output:
// Today is day 1, and tomorrow is day 2.
Each pair of curly braces is replaced with the result of the expression inside it.
Fill in the blank

To create an interpolated string in C#, you place a ____ symbol directly before the opening quotation mark.

🤖
Curly braces are special here, so escaping them takes a little extra typing. 🔧

Because { and } now have a special meaning inside an interpolated string, you need to double them (using {{ and }}) if you actually want to print a literal curly brace.

Console.WriteLine($"{{Score}}: {100}");

// Output:
// {Score}: 100
The doubled {{ }} around "Score" print as literal braces, while the single { } around 100 is evaluated as an expression.
Quick check

What does this line output?

Console.WriteLine($"Total: {10 + 5}");
True or false

An interpolated string in C# must start with a $ symbol before the opening quotation mark.

🤖
This one habit will replace a lot of clunky concatenation later on. 🧵

String interpolation is usually the cleanest way to combine fixed text with calculated values, and most C# developers reach for it by default instead of gluing pieces of text together by hand.

Chapter quiz

Output

10 questions · pass with 60% — just like in the app.

Quick check

What happens automatically after Console.WriteLine("Hi"); outputs its text?

True or false

Console.Write() automatically adds a line break at the end, just like Console.WriteLine().

Fill in the blank

The escape character ____ produces a line break in the middle of a piece of text.

Quick check

What does this code output?

Console.Write("A ");
Console.WriteLine("test");
True or false

\t produces a tab that helps align text into columns.

Fill in the blank

To output a quotation mark directly inside a string, you write ____.

Quick check

Why do you have to write \\ to output a single backslash?

Fill in the blank

To create an interpolated string, you place a ____ symbol directly before the opening quotation mark.

Quick check

What does Console.WriteLine($"Total: {10 + 5}"); output?

True or false

To print a literal curly brace inside an interpolated string, you write it as {{ or }}.

Keep your streak going in Swipe Coding

Swipe through every level of C# on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →