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

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s