0Pricing
C# Academy · Lesson

Building Strings

Concatenation and StringBuilder.

Joining Strings With +

The simplest way to build a string is to join pieces with the + operator.

This is called concatenation. It works well for a few pieces, like combining a greeting with a name.

class Program
{
    static void Main()
    {
        string name = "Sam";
        string greeting = "Hi, " + name;
        System.Console.WriteLine(greeting);
    }
}

String Interpolation

Interpolation is a cleaner way to insert values into text.

Put a $ before the string and wrap variables in curly braces. The values are dropped into place automatically.

class Program
{
    static void Main()
    {
        string name = "Sam";
        int age = 9;
        System.Console.WriteLine($"{name} is {age}");
    }
}

All lessons in this course

  1. The char Type
  2. Char Helper Methods
  3. Iterating Over Strings
  4. Building Strings
← Back to C# Academy