Convert arraylist to string array
In this article, we will learn how to convert ArrayList to string array. The ToArray() method copies the elements of the ArrayList to a new string array.
In the code given below, we create and initialize the ArrayList. Using ToArray() method we copy the elements of the ArrayList to a string array and display the array.
Arrays vs ArrayList
how to create and add items into the ArrayList in csharp
how to add items to the arraylist using an add method
retrieve arraylist items using enumerators
retrieve arraylist items using for each loop
retrieve arraylist items using indexers
insert items to the arraylist using insert and insertrange method
remove items from arraylist
find item in arraylist using indexof method
In the code given below, we create and initialize the ArrayList. Using ToArray() method we copy the elements of the ArrayList to a string array and display the array.
public void ConvertArrayListToarray() { ArrayList myArrayList = new ArrayList(); myArrayList.Add("Jhon"); myArrayList.Add("Jill"); myArrayList.Add("Jo"); myArrayList.Add("Chris"); String[] myArray = (String[])myArrayList.ToArray(typeof(string)); string str = string.Empty; for (int i = 0; i < myArray.Length; i++) str += myArray[i] + "\n"; }
ArrayList Articles
- bind arraylist with gridview control in asp net application
- how to bind arraylist with dropdownlist in asp net application
- how to bind arraylist with radiobuttonlist in asp.net application
- convert string array to arraylist
- convert datatable into an arraylist
- convert dataset to arraylist in asp.net using c#
- how to retrieve arraylist items in reverse order
- difference between arraylist and list collection
Most Viewed
Azure Q & A
Azure Platform
Grid-View
GridView CommandField example
Details-View
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Entity Framework
Query entity data model using linq to entities
Array List
Difference between arraylist and list collection
Web Services
How to create a Web service using Visual Studio.net
Form-View
FormView DataBound Event
Object Oriented Programming
Calling base class constructor in C#
Linq
Convert a sequence to a generic list using ToList()method
Project Ideas
Project ideas for students
AccountingSoftware
Accounting Software
MVC
Creating an ASP.Net MVC 3 application
.Net
Using assemblies in .net applications
ASP .Net
How to implement form validation using ASP.Net 2.0 Validation Controls