Removing even number position elements from ArrayList in C#

CGN007
Posted by CGN007 under C# category on | Points: 40 | Views : 3333
using System;

using System.Collections;



namespace StudyBasics

{

class Program

{

static void Main(string[] args)

{

//Declaring the ArrayList

ArrayList arrayList = new ArrayList();



//Adding the element 1-10 in the arraylist

for (int i = 1; i < 11; i++)

arrayList.Add(i);



// remove even numbers from the arraylist

for (int i = 2; i < 11; i += 2)

arrayList.Remove(i);



// Printing the arraylist elemets.Now it only contains the odd numbers.

foreach (int i in arrayList)

Console.WriteLine(i);



Console.ReadKey();

}

}

}

Comments or Responses

Login to post response