The Join () method in strings concatenates all the elements of a string array, using the specified separator between each element.
In the below example we have a multi-line string and we have set the separator as “\n” −
String.Join("\n", starray);Example
The following is the complete example −
using System;
namespace StringApplication {
class StringProg {
static void Main(string[] args) {
string[] starray = new string[]{"Down the way nights are dark",
"And the sun shines daily on the mountaintop",
"I took a trip on a sailing ship",
"And when I reached Jamaica",
"I made a stop"};
string str = String.Join("\n", starray);
Console.WriteLine(str);
}
}
}Output
Down the way nights are dark And the sun shines daily on the mountain top I took a trip on a sailing ship And when I reached Jamaica I made a stop