DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

.NET program to convert list string to comma separated string

By Ashok Nalam on 29 Jan 2014 | Category: C# | Tagged: string list 
The snippet shows how to convert list of string values to comma separated string values in quicker way using String.Join method.
  Discuss Add Comment   |  
Add rating Rate this resource   

The snippet shows how to convert list of string values to comma separated string values in quicker way using String.Join method.

String.Join:

String.Join(String separator, IEnumerable<String> values) - Concatenates the elements of members of a collection using specified character between each element.

Input Arguments:
separator - string to use as a separator
values - A collection which contains strings to concatenate

Output
Returns separator separated collection values

Example:

using System;
using System.Collections.Generic;
namespace DotNetMirror
{
    class ListString2CommaSeparatedString
    {
        static void Main()
        {
            List<string> listValues = new List<string>();
            listValues.Add("D");
            listValues.Add("N");
            listValues.Add("M");

            string commaSeparatedString = string.Join(",", listValues);
            Console.WriteLine(commaSeparatedString);
            Console.ReadLine();
        }
    }
}

Output:

D,N,M

  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 9526  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.
 
cheap jordans|wholesale air max|wholesale jordans|wholesale jewelry|wholesale jerseys