Menu
Coddy logo textTech

Concatenation

Lesson 2 of 14 in Coddy's Strings and Arrays in C# course.

It's possible to combine strings using the + operator,

string str1 = "Hello";
string str2 = "World";
Console.WriteLine(str1 + " " + str2);

The string "Hello World" will be printed in the above example.

Note the space (" ") added in between str1 and str2

Or, use the concat() method,

string str1 = "Hello ";
string str2 = "World";
Console.WriteLine(str1.Concat(str2));
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

challenge icon

Challenge

Easy

Write a function named createFullName that gets two strings as arguments, the first name and the last name, and returns the concatenation of the two strings with a space in between.

Try it yourself

using System;

class CreateFullName {
    public static string createFullName(string firstName, string lastName) {
        // Write code here
    }
}

All lessons in Strings and Arrays in C#