Working with Text
7 min · C#
Join strings, measure them, and format text with String tools.
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.
Rena
Your AI tutor. She walks you through each step.
Asking for help is part of coding. Rena reads your code and gives you a hint. She is free with an account: 20 hints a day.