Khai báo một chuỗi và thêm các phần tử -
string[] str = { "One", "Two", "Three", "Four", "Five" }; Sử dụng phương thức Join () để nối các từ−
string res = string.Join(" ", str); Hãy cho chúng tôi xem mã hoàn chỉnh -
Ví dụ
using System;
public class Demo {
public static void Main() {
string[] str = { "One", "Two", "Three", "Four", "Five" };
// join words
string res = string.Join(" ", str);
Console.WriteLine(res);
}
} Đầu ra
One Two Three Four Five