Tuesday, April 7, 2009

Extension Method to Join Strings with a Delimiter

String ArrayI was talking with my coworker James Brechtel today about writing an extension method to join an array of strings together with a delimiter like string.Join() does. I'd prefer string[].Join() because it seems more fluent.

After I put the IList<T>.ToArray<T>() extension method together, implementing the fluent style join was a simple task.

Here's what that looks like:
public static string Join(this IList<string> list, string separator)
return string.Join(separator, list.ToArray());
That's it! :)

No comments:

Post a Comment