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


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

294 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements