convert string array to arraylist
In this article, we will learn how to convert string array into an arraylist. In the previous article we have seen how to convert arraylist to string array.
In the code given below, we declare a string array and assign values to each element in the array.
Next, we create a new arraylist of type string. We use AddRange method we can convert string array to an arraylist. We need to pass the array to the AddRange method as a parameter as shown in the code given below.
public partial class _Default : System.Web.UI.Page { string connectionString = "Data Source=LocalHost; Initial CataLog=ERPFinAccounting; User ID=kris; Password=XXX"; protected void Page_Load(object sender, EventArgs e) { ArrayList StringArrayList = ConvertStringArrayToArrayList(); string str = string.Empty; foreach (string name in StringArrayList) { str += name + "\n"; } } } public ArrayList ConvertStringArrayToArrayList() { string[] myArray = new string[5]; myArray[0] = "Jhon"; myArray[1] = "Jill"; myArray[2] = "JO"; myArray[3] = "Chris"; ArrayList StringArraytoArrayList = new ArrayList(myArray.Length); StringArraytoArrayList.AddRange(myArray); return StringArraytoArrayList; }
ArrayList Articles
- insert items to the arraylist using insert and insertrange method
- remove items from arraylist
- find item in arraylist using indexof method
- 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 arraylist to string array
- 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
- 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
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