(no subject)

May 27, 2009 16:27

Huzzah! I love Extension Methods :)

This one I wrote today will take a delegate or lambda and use it to automatically create a delimited list from an IEnumerable of T:

public static string Delimit(this IEnumerable enumerable, Func toStringConverter, string delimiter)
    {
        string result = string.Empty;
        enumerable.ForEach(s => result += toStringConverter(s) + delimiter);
        return result.Length > delimiter.Length ? result.Substring(0, result.Length - delimiter.Length) : result;
    }
Previous post
Up