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 betweenstr1andstr2
Or, use the concat() method,
string str1 = "Hello ";
string str2 = "World";
Console.WriteLine(str1.Concat(str2));This lesson includes a short quiz. Start the lesson to answer it and track your progress.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
Challenge
EasyWrite 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
}
}