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
Simple and straight to the jugular.