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



6 comments:
Excellent! I love your style. Thank you for sharing.
Xesco from Barcelona. Spain.
You were soooo..... GREAT!!
This is really a good way of thinking.
Thanks a million...
Simple and straight to the jugular.
Your Idea is excellent...But why do you need unnecessary overloads?
thank you very much, it works perfectly!
Post a Comment