Convert List into Comma Separated String C#

How to convert a list into a comma seprated string using c#.net in .net core. To convert list into comma separated string will use string.Join().
In today article I will show a simple tutorial with example how you can convert a list into a comma separated string using  string.Join() in .NET core using c#.net. So, for this example, we will create a new .net core console application and the below code. 

Convert List to Comma Separated String Using string.Join()

To convert the list into comma separated string we will use an inbuilt string.Join() method. So, suppose we are having the below mention list.

 List<string> nameDataList = new List<string>()
{
    "User 1",
    "User 2",
    "User 3",
    "User 4"
}; 
In above list i have added user names in the user list. Now let's check code how we can convert the list of string into comma separated string using string.Join().
string finalString=string.Join(", ", nameDataList);
Console.WriteLine(finalString);
Console.ReadLine(); 
In above code I have converted the list into string having comma value. Now lets run the code by putting a break point. 

List to Comma separated string

In above code we can see we are getting the list of users in a comma separated string.  Now let's press F5 to check the final output. 

List to String In c#

Post a Comment