Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert ArrayList into string array(string[]) in c#

Tags:

How can I convert ArrayList into string[] in C#?

like image 576
Praveen Kumar Avatar asked Jan 19 '12 10:01

Praveen Kumar


People also ask

How do you turn an ArrayList into a String?

To convert the contents of an ArrayList to a String, create a StringBuffer object append the contents of the ArrayList to it, finally convert the StringBuffer object to String using the toString() method.

Can we convert String [] to String?

So how to convert String array to String in java. We can use Arrays. toString method that invoke the toString() method on individual elements and use StringBuilder to create String. We can also create our own method to convert String array to String if we have some specific format requirements.

How do I return an array from a list in C#?

You can just put return null; or return new ArrayList(); since it looks like you don't care with what you're gonna get with the catch. You already have a console log.


2 Answers

string[] myArray = (string[])myarrayList.ToArray(typeof(string)); 
like image 76
Mustafa Ekici Avatar answered Sep 22 '22 12:09

Mustafa Ekici


use .ToArray(Type)

string[] stringArray = (string[])arrayList.ToArray(typeof(string)); 
like image 45
Renatas M. Avatar answered Sep 23 '22 12:09

Renatas M.