append a string to the end of another string in csharp

To append a string to the end of another string in C#, you can use the + operator or the string.Concat method. Here's an example using the + operator:

main.cs
string str1 = "Hello";
string str2 = "World";
string str3 = str1 + " " + str2; // "Hello World"
96 chars
4 lines

And here's an example using the string.Concat method:

main.cs
string str1 = "Hello";
string str2 = "World";
string str3 = string.Concat(str1, " ", str2); // "Hello World"
109 chars
4 lines

Both of these methods will create a new string with the concatenated result. Note that strings are immutable in C#, so any operation that modifies a string actually creates a new string object.

gistlibby LogSnag