Insert method in ArrayList
In this article I will explain the Insert method of arraylist.
Insert method inserts an element into the ArrayList at the specified index.
Example
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ArrayList numbers = new ArrayList();
numbers.Add(10);
numbers.Add(22);
numbers.Add(3);
numbers.Add(5);
numbers.Add(9);
Console.WriteLine("The elements of the arraylist are:");
foreach (int i in numbers)
{
Console.WriteLine(i);
}
numbers.Insert(0, "One");
numbers.Insert(4, "Two");
numbers.Insert(5, "Three");
Console.WriteLine("After performing the insert operation the arraylist is:");
foreach (object i in numbers)
{
Console.WriteLine(i);
}
}
}
}
|
Output
Further Readings
You may also want to read these related articles.
Ask Your Question
Got a programming related question? You may want to post your question here