Mega Code Archive

 
Categories / C# / Collections Data Structure
 

IEnumerable To Comma String

using System.Collections.Generic; using System.Linq; using System.Text; public static class CollectionExtensions {     public static string ToCommaString<T>(this IEnumerable<T> tArray)     {         if (tArray.Count() == 0) return string.Empty;         var buffer = new StringBuilder();         int count = 0;         bool end = false;         foreach (var t in tArray)         {             if (count == tArray.Count() - 1) end = true;             if (end)                 buffer.AppendFormat("{0}", t.ToString());             else                 buffer.AppendFormat("{0},", t.ToString());             count++;         }         return buffer.ToString();     } }