示例#1
0
        static void TestRemove(A_Hashtable <int, string> ht)
        {
            try
            {
                //ht.Remove(11);
                ht.Remove(1);
                ht.Remove(111);
            }
            catch (ApplicationException e)
            {
                Console.WriteLine(e.Message);
            }

            //ht.Remove(99999);
        }
示例#2
0
        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();
        }