C# program to convert several strings into a single comma-delimited string

CsharpProgrammingServer Side Programming

Set the strings −

List<string> val = new List<string>();

// list of strings
val.Add("water");
val.Add("food");
val.Add("air");

Use Join method to convert several strings into a single comma-delimited string −

string.Join(",", val.ToArray());

Here is the complete code −

Example

 Live Demo

using System;
using System.Collections.Generic;
public class Demo {
   public static void Main() {
      List<string> val = new List<string>();
      // list of strings
      val.Add("water");
      val.Add("food");
      val.Add("air");
      string res = string.Join(",", val.ToArray());
      Console.WriteLine(res);
   }
}

Output

water,food,air
raja
Published on 04-Sep-2018 16:02:30
Advertisements