Method I Wish Was There: string.Join

Yes, I know it is there as a static, but I want it as a method on IEnumerable<string>.

public static string Join(this IEnumerable<string> source, string joiner)
{
            if (source.Count() == 0)
                return "";
            return source.Aggregate((a,b) => a+ joiner + b);
}

So that when I’ve got some strings I can join them 🙂

var logmessage = people.Select(p=>p.Firstname).Join(“, “);

2 thoughts on “Method I Wish Was There: string.Join”

Comments are closed.