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);
image

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);
            Console.WriteLine(commaseperatedstring);

            Console.ReadLine();
        }
    }
}
    
Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Hey, wait!Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

You cannot copy content of this page