Exemplo n.º 1
0
        private static void ReadPhoneEntries(
            string path, PhoneBook phoneBook)
        {
            string line;
            using (System.IO.StreamReader reader = new System.IO.StreamReader(path))
            {
                while ((line = reader.ReadLine()) != null)
                {
                    PhoneBookEntry newEntry;
                    var phoneEntry = line.Split('|');

                    var name = phoneEntry[0].Trim().Split(' ');
                    var town = phoneEntry[1].Trim();
                    var phone = phoneEntry[2].Trim();
                    if (name.Length < 3)
                    {
                        newEntry = new PhoneBookEntry(town, phone, phoneEntry[0].Trim());
                    }
                    else
                    {
                        newEntry = new PhoneBookEntry(name[0], name[1], name[2], town, phone);
                    }

                    phoneBook.Add(newEntry);
                }
            }
        }
        public void Add(string name,string town,string phone)
        {
            var entry = new PhoneBookEntry(name,town,phone);

            if (this.entries.ContainsKey(name))
            {
                this.entries[name].Add(entry);
            }
            else
            {
                this.entries.Add(name, new List<PhoneBookEntry>() { entry });
            }

            foreach (string subname in name.Split())
            {
                if (this.names.ContainsKey(subname))
                {
                    this.names[subname].Add(name);
                }
                else
                {
                    this.names.Add(subname, new HashSet<string>() { name });
                }
            }
        }
Exemplo n.º 3
0
 public void Add(PhoneBookEntry entry)
 {
         FirstNames.Add(entry.FirstName, entry);
         MiddleNames.Add(entry.MiddleName, entry);
         LastNames.Add(entry.LastName, entry);
         NickNames.Add(entry.NickName, entry);
         Towns.Add(entry.Town, entry);
 }