Joining with + works but gets unreadable fast. Put a $ before the quotes and you can write variables in braces.
The same line, two ways
With +
C#
Console.WriteLine("Hi " + name + ", you are " + age);With $
C#
Console.WriteLine($"Hi {name}, you are {age}");This is string interpolation. The second form reads like the sentence it produces, and it is what you will see in modern C#.
Program.cs
using System;
class Program
{
static void Main()
{
string city = "Vienna";
int visitors = 12;
Console.WriteLine($"{visitors} people went to {city}");
}
}
Output
12 people went to Vienna
Do not forget the $
Without it, C# prints the braces literally: {visitors} people went to {city}. If you see that, you know what is missing.