In this C# tutorial, I will explain how to convert a list to a comma separated string in C#. There are various methods to convert a list to a comma separated string in C#.
Convert a List to a Comma Separated String in C#
Below are the 3 different methods to convert a list to a comma separated string in c#.
- Using string.Join() Method
- Using StringBuilder Class
- Using for Loop
Using string.Join() Method
The simplest and most straightforward method for converting a list to a comma-separated string is the string.Join() method in C#. Here is a complete code for converting a list to a comma separated string in C#.
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<string> myList = new List<string> { "apple", "banana", "cherry" };
string result = string.Join(",", myList);
Console.WriteLine(result);
}
}
Once you run the above code using Visual Studio, you can see the output, like the screenshot below:

Using StringBuilder Class
If you want more control over the format of the output or if you are dealing with a large list, using the StringBuilder class might be more appropriate. Below is the complete code to convert a list to a comma separated string in C# using the StringBuilder class.
using System;
using System.Collections.Generic;
using System.Text;
class Program
{
static void Main()
{
List<string> myList = new List<string> { "New York", "California", "Chicago" };
StringBuilder sb = new StringBuilder();
for (int i = 0; i < myList.Count; i++)
{
sb.Append(myList[i]);
if (i < myList.Count - 1)
{
sb.Append(",");
}
}
Console.WriteLine(sb.ToString());
}
}
Once you run the code, you can see the output below:

Using for Loop
If you prefer the traditional approach, you can use a for loop to iterate over the list and concatenate the strings with commas. Here is the complete code to convert a list to a comma separated string in C#.
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<string> myList = new List<string> { "Chicago", "San Francisco", "Dallas" };
string result = "";
for (int i = 0; i < myList.Count; i++)
{
result += myList[i];
if (i < myList.Count - 1)
{
result += ",";
}
}
Console.WriteLine(result);
}
}
Once you run the code, you can see the output below in the screenshot.

Conclusion
In this C# tutorial, I have explained how to convert a list to a comma-separated string in C#. We explored three primary techniques for converting a list to comma separated string in C#: using string.Join, employing StringBuilder, and utilizing a traditional for loop.
You may also like:
- Check if a String Array Contains a Specific Element in C#
- How to Add Values to a String Array in C#?
- Convert Object to Comma Separated String in C#
Bijay Kumar is a renowned software engineer, accomplished author, and distinguished Microsoft Most Valuable Professional (MVP) specializing in SharePoint. With a rich professional background spanning over 15 years, Bijay has established himself as an authority in the field of information technology. He possesses unparalleled expertise in multiple programming languages and technologies such as ASP.NET, ASP.NET MVC, C#.NET, and SharePoint, which has enabled him to develop innovative and cutting-edge solutions for clients across the globe. Read more…