Lesson 7: String interpolation
Concatenation with + works, but it's easy to forget spaces and get tangled. A cleaner way is interpolation: put a $ before the string, then write a variable name inside curly braces {}. For example $"Hello, {name}!" replaces {name} with the value. Note: in C# the sign is $ (not f like Python), and w
Interpolation is like a form with blanks: $ says 'fill in the blanks', and each {name} is filled with the variable's value.
- interpolation $""
- A string starting with $, where {name} is replaced by the variable's value.
- placeholder {}
- The curly braces where you write a variable name to embed its value.
- the $ sign
- Marks that C# should treat {} as variables. Without it {} stays text.