Lesson 3 of 15
String Interpolation
Working with Strings
C# strings support interpolation with the $ prefix — embed expressions directly inside curly braces:
string name = "Alice";
int age = 30;
Console.WriteLine($"My name is {name} and I am {age} years old.");
// Output: My name is Alice and I am 30 years old.
You can also perform operations inside the braces:
double price = 9.99;
int qty = 3;
Console.WriteLine($"Total: {price * qty:F2}");
// Output: Total: 29.97
Common String Operations
string s = "Hello, World!";
Console.WriteLine(s.Length); // 13
Console.WriteLine(s.ToUpper()); // HELLO, WORLD!
Console.WriteLine(s.ToLower()); // hello, world!
Console.WriteLine(s.Contains("World")); // True
Console.WriteLine(s.Replace("World", "C#")); // Hello, C#!
Console.WriteLine(s.Substring(7, 5)); // World
Your Task
Given string city = "Paris" and int year = 2024, print:
Paris hosted the Olympics in 2024.WasmSharp (.NET) loading...
Loading...
Click "Run" to execute your code.