- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Adding elements to the end of the ArrayList in C#
To add elements to the end of the ArrayList, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList list = new ArrayList(); list.Add("Andy"); list.Add("Gary"); list.Add("Katie"); list.Add("Amy"); Console.WriteLine("Elements in ArrayList..."); foreach (string res in list) { Console.WriteLine(res); } string[] strArr = { "John", "Jacob" }; list.AddRange(strArr); Console.WriteLine("Elements in ArrayList...UPDATED"); foreach(String str in list) { Console.WriteLine(str); } } }
Output
This will produce the following output −
Elements in ArrayList... Andy Gary Katie Amy Elements in ArrayList...UPDATED Andy Gary Katie Amy John Jacob
Example
Let us see another example −
using System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList list = new ArrayList(); list.Add("Andy"); list.Add("Gary"); list.Add("Katie"); list.Add("Amy"); Console.WriteLine("Elements in ArrayList..."); foreach (string res in list) { Console.WriteLine(res); } string[] strArr = { "John", "Jacob" }; list.AddRange(strArr); Console.WriteLine("Elements in ArrayList...UPDATED"); foreach(String str in list) { Console.WriteLine(str); } string[] strArr2 = { "Tim", "Tom", "David" }; list.AddRange(strArr2); Console.WriteLine("Elements in ArrayList...UPDATED"); foreach(String str in list) { Console.WriteLine(str); } } }
Output
This will produce the following output −
Elements in ArrayList... Andy Gary Katie Amy Elements in ArrayList...UPDATED Andy Gary Katie Amy John Jacob Elements in ArrayList...UPDATED Andy Gary Katie Amy John Jacob Tim Tom David
- Related Articles
- Adding the elements of the specified collection to the end of the List in C#
- Adding elements in the middle of an ArrayList in Java
- Add an object to the end of the ArrayList in C#
- Copying the elements of ArrayList to a new array in C#
- Adding new node or value at the end of LinkedList in C#
- Set the capacity to the actual number of elements in the ArrayList in C#?
- Copy the elements of collection over a range of elements in ArrayList in C#
- Remove a range of elements from the ArrayList in C#
- Remove all elements from the ArrayList in C#
- Get the number of elements actually contained in the ArrayList in C#
- Adding an element at the end of the array in Javascript
- C# Program to skip elements of an array from the end
- Maximize the median of the given array after adding K elements to the same array in C++
- Getting an enumerator for a range of elements in the ArrayList in C#
- Get or set the number of elements that the ArrayList can contain in C#

Advertisements