Insert and remove of an element from an array :

How to remove an element from an array : 


class Program
{
static void Main()
{
ArrayList list = new ArrayList()
list.Add(“Imrez”);
list.Add(“Khan”);
list.Add(“Ratin”);

list.RemoveAt(1);        // It removes the element of  1st position which is “Khan”.

foreach (string i in list)
{
Console.WriteLine(i);
Console.ReadLine();
}
}
}
Output :
Imrez
Ratin
———————–*———————

How to insert an element in an array :

class Program
{
static void Main()
{
ArrayList list = new ArrayList()
list.Add(“Imrez”);
list.Add(“Khan”);
list.Add(“Ratin”);

list.Insert(0,”Mr.”);   //It insert an element in zero number position which is “Mr.”

foreach (string i in list)
{
Console.WriteLine(i);
Console.ReadLine();
}
}
}
Output :
Mr.
Imrez
Khan
Ratin
———————–*———————

Leave a Reply