by Sai gowtham

How to create a comma separated string from List string in C#

To create a comma separated string from a list string, we can use the String.join() method in C#.

Here is an example that converts myList to commaString.

using System;
using System.Collections.Generic;

class ConvertEnum {
 static void Main() {

  IList<string> myList = new List<string>{"Hello","1","testing","2"};
  string commaString = string.Join(",", myList);

     System.Console.WriteLine(commaString);
  }
}

Output:

Hello,1,testing,2

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course