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

CsharpProgrammingServer Side Programming

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
raja
Published on 04-Sep-2018 08:29:39
Advertisements