using System; using System.Collections.Generic; using System.Text; public static class IEnumerableRocks { public static string Implode (this IEnumerable self, string separator, Func selector) { return Implode (self, separator, (b, e) => { b.Append (selector (e).ToString ()); }); } public static string Implode (this IEnumerable self, string separator, Action appender) { var coll = self as ICollection; if (coll != null && coll.Count == 0) return string.Empty; bool needSep = false; var s = new StringBuilder (); foreach (var element in self) { if (needSep && separator != null) s.Append (separator); appender (s, element); needSep = true; } return s.ToString (); } } class Test { public static void Main () { Console.WriteLine (new [] { "foo", "bar" }.Implode (", ", e => "'" + e + "'")); } }