static void TestAdd(A_Hashtable <int, string> ht) { try { ht.Add(1, "Key 1"); ht.Add(11, "Key 11"); ht.Add(111, "Key 111"); ht.Add(47595, "bas"); } catch (ApplicationException e) { Console.WriteLine(e.Message); } }
static void LoadDataFromFile(A_Hashtable <Person, Person> ht) { StreamReader sr = new StreamReader(File.Open("People.txt", FileMode.Open)); string sInput = ""; try { //Read a line from the file while ((sInput = sr.ReadLine()) != null) { try { char[] cArray = { ' ' }; string[] sArray = sInput.Split(cArray); int iSSN = Int32.Parse(sArray[0]); Person p = new Person(iSSN, sArray[2], sArray[1]); ht.Add(p, p); } catch (ApplicationException ae) { Console.WriteLine("Exception: " + ae.Message); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } sr.Close(); }
static void LoadDataFromFileAndRemove(A_Hashtable <Person, Person> ht) { StreamReader sr = new StreamReader(File.Open("People.txt", FileMode.Open)); string sInput = ""; ArrayList al = new ArrayList(); int iCount = 0; try { //Read a line from the file while ((sInput = sr.ReadLine()) != null) { try { char[] cArray = { ' ' }; string[] sArray = sInput.Split(cArray); int iSSN = Int32.Parse(sArray[0]); Person p = new Person(iSSN, sArray[2], sArray[1]); if (p.SSN == 478403546) { Console.WriteLine(""); } ; ht.Add(p, p); if (iCount % 10 == 0) { al.Add(p); } iCount++; } catch (ApplicationException ae) { Console.WriteLine("Exception: " + ae.Message); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Count before removing: " + ht.Count); //Remove every tenth person that is actually in the list. try { foreach (Person p in al) { ht.Remove(p); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Count after removing: " + ht.Count); sr.Close(); }