How many times have you written code similar to this?
I have hopefully done it for the last time since I created a couple of extension methods for IEnumerable<string>, well actually, one method with a couple of overloads.
The first one is really simple and just concatenates all the strings in the specified collection to a single string, something like:
In this case the result variable will contain the string “foobar”. One of the overloads will let you specify a separator:
Now the result is “foo, bar”.
And the last one will let you specify a prefix and a suffix in addition to the separator:
Giving you the result “(foo, bar)”. Quite neat!
Here’s the code for the extensions:
… and some NUnit-tests: