Mega Code Archive

 
Categories / C# / Data Types
 

Format Array To Comma Delimited String

using System; using System.Collections.Generic; using System.Text; using System.Globalization; internal static class Utility {     public static string FormatArrayToCommaDelimitedString<T>(T[] items) where T : IFormattable     {         return FormatArrayToCommaDelimitedString(items, CultureInfo.InvariantCulture);     }     public static string FormatArrayToCommaDelimitedString<T>(T[] items, IFormatProvider formatter) where T : IFormattable     {         if (items.Length == 0)             return string.Empty;         StringBuilder sb = new StringBuilder();         sb.Append(items[0].ToString(null, formatter));         for (int i = 1; i < items.Length; i++)         {             sb.AppendFormat(formatter, ",{0}", items[i]);         }         return sb.ToString();     } }