A small change

This is a small tid-bit of an extension method I created when I realized that the ability to combine a collection of strings into a character-separated string was only available as a static method of the String class:

public static string Join(this IEnumerable<string> strings, string separator) {
    return String.Join(separator, strings);
}

This allows me to achieve the following, which I would argue is slightly more intuitive:

var myListOfStrings = new List<string> {"January", "February", "March"};
var myCombinedListOfString = myListOfStrings.Join(",");

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s