Follow in Twitter & Facebook


Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools


Tuesday, May 15, 2012

Convert ArrayList to String using C#

In this C#.Net article we will discuss how to covert an arraylist to a string using C#.Net. You can also check my last article on Arraylist,Hash table,Sorted list and Dictionary C#.Net.

To covert an arraylist to string we can use the built in fuction 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();
arrayList.Add("First String");

arrayList.Add("Second String");
arrayList.Add(
"Third String");

//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:
First String|Second String|Third String




0 on: "Convert ArrayList to String using C#"