IList To Comma String - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

IList To Comma String

Demo Code


using System.Text;
using System.Collections.Generic;

public class Main{

        public static string ToCommaString<T>(IList<T> collection)
        {/*  w ww  .j  a  v  a 2s .  c  o  m*/
            if (collection.Count == 0)
                return string.Empty;

            var buffer = new StringBuilder();

            for (int i = 0; i < collection.Count; i++)
            {
                if (i == collection.Count - 1)
                    buffer.Append(collection[i]);
                else
                    buffer.AppendFormat("{0},", collection[i]);
            }

            return buffer.ToString();
        }
}

Related Tutorials