0Pricing
C# Academy · Lesson

String Interpolation Basics

Embed expressions directly inside strings.

Interpolated Strings

An interpolated string starts with a dollar sign before the opening quote. Inside, you place expressions in curly braces, and C# inserts their values.

using System;

class Program {
    static void Main() {
        string name = "Ada";
        Console.WriteLine($"Hello, {name}!");
    }
}

Embedding Expressions

The braces can hold any expression, not just a variable. C# evaluates it and converts the result to text.

using System;

class Program {
    static void Main() {
        int a = 3, b = 4;
        Console.WriteLine($"Sum is {a + b}");
    }
}

All lessons in this course

  1. String Interpolation Basics
  2. Composite Formatting with string.Format
  3. Numeric and Date Format Specifiers
  4. Raw String Literals
← Back to C# Academy