In this example, i’ll show you How to add and concatenate string in C#.
Plus Operator
1 2 3 |
string str2 = "csharp" + str1; |
Example
Let us see an example of + operator to concatenate strings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
using System; class Program { static void Main() { string str1 = "csharp"; // concatenation string str2 = "examples" + str1; Console.WriteLine(str2); } } |
Output:
csharpexamples
String.concat
Example
Let us see an example of string.concat to concatenate strings in C# −
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
using System; class Program { static void Main() { string str1 = "csharp"; // concatenation string str2 = string.Concat("examples", str1); Console.WriteLine(str2); } } |
Output:
csharpexamples