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(“, “);

Tags:

2 Responses to “Method I Wish Was There: string.Join”

  1. I really like your “Method I Wish Was There”-series. Did you consider tagging them specifically as such?

  2. jrwren says:

    I did not, but I will do so in the future.

Leave a Reply