New! GraphQL.NET Cookbook by Senthil Kumar Balu

C# Tips and Tricks #13 – Create Comma seperated string from a List.

Assume that you have a List of string and you wish you to get the items of the list into a comma separated string , you will be able to it easily do with the help of string.join method.

How to generate a comma seperated string from a list in C# ?

Assume that the list contains three items Senthil , Kumar , CredAbility as shown below.

IList&lt;string&gt; lst = new List<string>{"Senthil","Kumar","CredAbility"};

To get the comma seperated string of all the items in the list , use the string.Join as shown below.

string commaseperatedstring = string.Join(",", lst);

Here’s the full code snippet that is used in this example.

using System;
using System.Collections.Generic;

namespace ConsoleApp1
    class Program
        static void Main(string[] args)
            IList<string> lst = new List<string> { "Senthil", "Kumar", "CredAbility" };
            string commaseperatedstring = string.Join(",", lst);

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.