Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

โปรแกรม C# เพื่อรวมคำเป็นสตริงใน C #


ประกาศสตริงและเพิ่มองค์ประกอบ -

string[] str = { "One", "Two", "Three", "Four", "Five" };

ใช้วิธี Join() เพื่อเชื่อมคำ-

string res = string.Join(" ", str);

ให้เราดูรหัสที่สมบูรณ์ -

ตัวอย่าง

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);
   }
}

ผลลัพธ์

One Two Three Four Five