Hi,
You can find generic solution for your case on internet.
Here is what I found:
public static class ExtensionMethods
{
public static string ToString<t>(this IEnumerable<t> source, string separator)
{
if (source == null)
throw new ArgumentException("Parameter source can not be null.");
if (string.IsNullOrEmpty(separator))
throw new ArgumentException("Parameter separator can not be null or empty.");
string[] array = source.Where(n => n != null).Select(n => n.ToString()).ToArray();
return string.Join(separator, array);
}
public static string ToString(this IEnumerable source, string separator)
{
if (source == null)
throw new ArgumentException("Parameter source can not be null.");
if (string.IsNullOrEmpty(separator))
throw new ArgumentException("Parameter separator can not be null or empty.");
string[] array = source.Cast<object>().Where(n => n != null).Select(n => n.ToString()).ToArray();
return string.Join(separator, array);
}
}
</t></t></t>
Example of using this extension method:
ArrayList myArrayList = new ArrayList();
myArrayList.Add("Item1");
myArrayList.Add("Item2");
myArrayList.Add("Item3");
myArrayList.Add("Item4");
myArrayList.Add("Item5");
string myListAsString = myArrayList.ToString("; ");
Output:
Item1; Item2; Item3; Item4; Item5