You are on page 1of 1

Lloyd Trista M.

Dagoc

2F5

Data Structure with Algorithm

String interpolation is a feature in C# that allows you to embed expressions directly in string literals. It
provides a more readable and concise way to create strings by embedding the values of variables directly
within the string. You can use the $ symbol before the string, and then insert expressions enclosed in
curly braces {} within the string. Here's an example:

using System;

class Program

static void Main()

string name = "John";

int age = 30;

// String interpolation

string message = $"Hello, my name is {name} and I am {age} years old.";

Console.WriteLine(message);

// You can also include expressions

int nextAge = age + 1;

string nextMessage = $"Next year, I'll be {nextAge}.";

Console.WriteLine(nextMessage);

In the example above, the variables name and age are directly embedded within the string using string
interpolation. The expressions inside the curly braces can be as simple or as complex as needed.

You might also like