Convert ArrayList to String (C#, VB.NET)

A function (with overloads, for char or string deliminator) for converting an ArrayList to a string (with defined deliminator). When calling with ArrayListToString(MyArrayList), default deliminator is ,.

C#

public string ArrayListToString(System.Collections.ArrayList ar)
{
 return ArrayListToString(ar, ',');
}
public string ArrayListToString(System.Collections.ArrayList ar, char delim)
{
 return ArrayListToString(ar, delim.ToString());
}
public string ArrayListToString(System.Collections.ArrayList ar, string delim)
{
 return string.Join(delim, (string []) ar.ToArray(typeof(string)));
}

VB.NET

Public Overloads Function ArrayListToString(ByVal ar As System.Collections.ArrayList) As String
 Return ArrayListToString(ar, ","C)
End Function

Public Overloads Function ArrayListToString(ByVal ar As System.Collections.ArrayList, ByVal delim As Char) As String
 Return ArrayListToString(ar, delim.ToString)
End Function

Public Overloads Function ArrayListToString(ByVal ar As System.Collections.ArrayList, ByVal delim As String) As String
 Return String.Join(delim, CType(ar.ToArray(GetType(String)), String()))
End Function

Comments

Xesco said…
Excellent! I love your style. Thank you for sharing.

Xesco from Barcelona. Spain.
Anonymous said…
You were soooo..... GREAT!!
Anonymous said…
This is really a good way of thinking.
Coffeeyesplease said…
Thanks a million...
Simple and straight to the jugular.
Unknown said…
Your Idea is excellent...But why do you need unnecessary overloads?
Caio said…
thank you very much, it works perfectly!

Popular posts from this blog

Link: HTML Agility Pack (.NET)

Basic Excel Spreadsheet Generation (ASP/ASP.NET)

ASP.NET: Binding alphabet to dropdown list