How to remove TopMost element from ArrayList in C #

I have an Arraylist. In which I want to remove one top element from an Arraylist (i.e. POP in Stack), I used the .Remove () method, but it does not work. Since I can only remove one element from arraylist

For example, if arraytlist contains 96,97,98,99,100 when .RemoveAt (0) is used. Its going to delete element 96, I want to delete element 100 from arraylist, So how can I remove this top element?

+3
source share
5 answers

Try using RemoveAt :

ArrayList list = …

// remove the last item
list.RemoveAt(list.Count - 1);
+1
source

You can try using RemoveAt :

ArrayList ar = new ArrayList();
ar.Add("Delete");
ar.Add("The");
ar.Add("Top element");

ArrayList.RemoveAt(0);

Deletes an element at the specified ArrayList index.

, :

, , , , . , . , , -.

+1

Try

First you will find the length of the array using the code below

int length = yourarray.Length;

next put this length in removeat

yourarray.RemoveAt(length - 1);
+1
source
int[] numbers = { 1, 3, 4, 9, 2, 4 };
int numToRemove = 1;
int numIdx = Array.IndexOf(numbers, numToRemove);
List<int> tmp = new List<int>(numbers);
tmp.RemoveAt(numIdx);
numbers = tmp.ToArray();
+1
source
ArrayList myAL = new ArrayList();
....
myAL.RemoveAt(myAL.Count - 1);
+1
source

All Articles