rdbandit

rdbandit

  • NA
  • 3
  • 0

Novice wishes to clear all members in an Arraylist

Mar 3 2005 4:56 PM
Hello! I wish to make a function that will remove ALL members in a class. This is the function my novice mind has created: //Remove all members in myDictionary private void DeleteAll() { foreach(Words w in myDictionary) { if (w.ID == 0) { myDictionary.Remove(w); } else break; } } This seems to clear all the Records but results in an ENDLESS LOOP! I don' think the "foreach" statements is the way to go, but I don't know any other options, everything I try fails. Can anyone steer me in the correct direction?? Here is a bit of backgroud of my class and Arraylist: my class Words.cs -------------------------------------- public class Words { public int ID; public string Word; public string Definition; public Words() { } } ----------------------------------------- The Form1 Function ---------------------------------------- public Form1() { // Required for Windows Form Designer support InitializeComponent(); // create the Dictionary myDictionary = new ArrayList(); } ---------------------------------------------------- Any help would be appreciated. i bet the solution is right under my nose. Feel free to poke fun of my dull mind. -Dominic

Answers (2)