Fun fact – System.String has 44 methods in .NET 4.7.1

Let’s say you have a collection of Strings you need to display as a CSV. Seems simple enough. It’s not difficult to write a method to loop the collection of Strings and build up one CSV. Then you realize you have an extra comma on the end. No problem, easy fix. Then you realize a list with zero items becomes a single comma. Again, not a huge problem. Then you start working through the next edge case and you wonder “hasn’t this been solved before?”. The answer is yes, an Microsoft made it a part of the .NET framework.

String.Join and it’s overloads are part of the 44 System.String methods. At its simplest form String.Join takes two arguments – a collection of strings and a separator. The method concatenates the collection separating each element with the string you specified. It doesn’t get much easier than that.

https://msdn.microsoft.com/en-us/library/dd783876(v=vs.110).aspx

Leave a Reply

Your email address will not be published. Required fields are marked *