I am trying to remove all occurrences of an item in the arraylist
ArrayList list=new ArrayList();
list.Add("2.2");
list.Add("2.5");
list.Add("2.6");
list.Add("2.2");
list.Add("2.5");
list.Add("2.2");
list.Remove("2.2")
Read the docs on ArrayList.Remove(), in particular:
Removes the first occurrence of a specific object from the ArrayList.
Why are you using an ArrayList
anyway? The elements in your example are all the same type, you would be better off using a List<string>
and then using RemoveAll e.g.
List<string> list = new List<string>();
list.add("2.2");
list.add("2.5");
list.add("2.6");
list.add("2.2");
list.add("2.5");
list.add("2.2");
list.RemoveAll(item => item == "2.2");