Python String Interpolation & Modern Formatting
Old-school string concatenation ("Hello " + name + " you have " + count + " items") is messy and error-prone. Modern C# provides string interpolation ($"...{expression}...") which lets you embed variables and math directly inside strings.
"String concatenation is like taping separate words onto a banner with Scotch tape. String interpolation ($) is like a smart fill-in-the-blank Mad Libs card that automatically plugs in the answers seamlessly."
Deep Dive: How It Works
The $ Prefix: Placing $ before double quotes unlocks { } expression placeholders: $"Hello, {userName}!".
Inline Expressions: You can execute math inside the brackets: $"Next year you will be {age + 1} years old.".
Format Specifiers: Format numbers directly: {price:C} (Currency: $19.99), {score:N0} (Comma separated: 1,000,000), {ratio:P1} (Percentage: 85.5%).
Verbatim Strings (@): @"C:\Users\Neo\Documents" ignores escape slashes.
Syntax Blueprint
string user = "Alex";
int level = 5;
Console.WriteLine($"Player {user} is Level {level}!");Prepend $ to string and place variables/expressions inside curly braces { }.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Putting the $ inside the quotes: "{user}"Why it happens: Forgetting the $ goes outside the string literal.
How to fix: Write $"Hello {user}".
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Use string interpolation
Declare string product = "Laptop"; and double price = 899.50;
Print "Item: Laptop costs $899.50" using string interpolation ($).
Finished reading and practicing?
Mark this lesson as completed to update your course progress.