From the course: C#: String Essential Training

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Combine strings with the concatenation operator

Combine strings with the concatenation operator - C# Tutorial

From the course: C#: String Essential Training

Combine strings with the concatenation operator

- Because combining strings is a common practice, the string class provides the plus operator for concatenating strings. This will make your code more readable. This example, I'm using the same strings from my previous example and I want to combine them. So I type in 'combo equal first' then the plus operator and then the second string. The plus operator's a binary operator, it has to have two arguments. The arguments are 'first' on the left side and 'second' on the right side. This will call the string 'dot concat method' to combine the two strings and output the results to the 'combo' variable. Like that. Of course, I can do multiple pluses. I'll go here and add 'plus florette' and now I'm combining three strings into one. The plus operator works with multiple data types. When you're using it on two strings, it does a concatenation operation. When you use it on numeric values, it usually does an addition operation.…

Contents