how to add items to the arraylist using an add method
ArrayList provides two methods to add items. These methods are Add and AddRange. Add method is used to store either be string, numeric or any custom objects into the ArrayList. In the code given below, we add customer names of string type to the ArrayList.
ArrayList also supports AddRange method to add items to the ArrayList. Using Add method we can add only one item at a time. But AddRange method allows us to add multiple items at a time into the ArrayList.
The picture given below is the result of the above code.
private void Form1_Load(object sender, EventArgs e) { ArrayList arrayList = new ArrayList(); arrayList.Add("Customer1"); arrayList.Add("Customer2"); arrayList.Add("Customer3"); arrayList.Add("Customer4"); arrayList.Add("Customer5"); The below code demonstrates how to add multiple items into the ArrayList using AddRange() method. string[] items = new string[]{ "Customer11","Customer12","Customer13","Customer14"}; arrayList.AddRange(items); string str = string.Empty; IEnumerator enumerator = arrayList.GetEnumerator(); while (enumerator.MoveNext()) { str += enumerator.Current.ToString() + "\n"; } MessageBox.Show(str); }
ArrayList also supports AddRange method to add items to the ArrayList. Using Add method we can add only one item at a time. But AddRange method allows us to add multiple items at a time into the ArrayList.
The picture given below is the result of the above code.

ArrayList Articles
- 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
- 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
- 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 string array to arraylist
- convert datatable into an arraylist
- convert dataset to arraylist in asp.net using c#
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