Phương thức Join() của chuỗi nối tất cả phần tử của mảng chuỗi, dùng dấu phân cách chỉ định giữa các phần tử.
Ví dụ dưới đây có mảng chuỗi nhiều dòng, dùng phân cách "\n":
String.Join("\n", starray);
Ví dụ
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);
}
}
}
Kết quả
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