C# program to join words into a string in C#



Declare a string and add elements −

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

Use the Join() method to join the words−

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

Let us see the complete code −

Example

 Live Demo

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

Output

One Two Three Four Five

Advertisements