Powered by Blogger.

Saturday, March 8, 2014

Convert ArrayList to String using C#.Net

In this post we will discuss how to convert ArrayList to String using C#.Net.

Also you can check out:

- Bind dropdownlist using arraylist or hashtable in C#.Net

- Hide all buttons in windows forms in C#.Net

- Triggers in sql server 2008

To covert an arraylist to string we can use the built in function join of String class. It is an overload method which takes one parameter as the separator and other parameter is the String[] array.

So we need to first convert the arraylist to a string array and then we can use the join method.
Suppose we have an array list like below:

ArrayList arrayList = new ArrayList();




//Now we can convert the arraylist to string array.
string[] stringArray = (string[])arrayList.ToArray(typeof(string));

//After that we will use the Join method to convert the string array to string. Here the string separator is '|'string finalResult = string.Join("|", stringArray);

So the result will come like below: