All lessons

Working with Text

7 min · C#

Join strings, measure them, and format text with String tools.

C# · Working with Text0/5 cleared

Enemy 1 of 5

Strings and concatenation

This code joins the text in greeting and name with the + sign and prints the combined text. Press Run to see it.

Why this works

Text in C# is stored as a string, and two strings can be joined together (concatenated) with the same + operator you use for adding numbers. C# figures out from the types on either side of + whether you mean "add these numbers" or "glue this text together".

Strings in C# are immutable, meaning once created, a string's contents never change in place: an operation like greeting + name always produces a brand new string rather than modifying greeting itself. That's why you either print the result directly or assign it to a new variable.

You
Packet Wolf
Loading editor…
Sign up to fightThis one runs on our servers, so it needs a free account.