Exemplo n.º 1
0
        public void Add(string entry)
        {
            var entryParts = entry.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(str => str.Trim()).ToList();
            var pbEntry    = new PhonebookEntry();

            var names = entryParts[0].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            switch (names.Length)
            {
            case 1:
                pbEntry.Nickname = names[0];
                break;

            case 2:
                pbEntry.FirstName = names[0];
                pbEntry.LastName  = names[1];
                break;

            case 3:
                pbEntry.FirstName  = names[0];
                pbEntry.MiddleName = names[1];
                pbEntry.LastName   = names[2];
                break;

            default:
                throw new ArgumentException();
            }

            pbEntry.Town        = entryParts[entryParts.Count - 2];
            pbEntry.PhoneNumber = entryParts[entryParts.Count - 1];

            entries.Add(entry.GetHashCode(), pbEntry);
        }
Exemplo n.º 2
0
 public void Add(PhonebookEntry entry)
 {
     entries.Add(entry.GetHashCode(), entry);
 }