public Dictionary <string, Contact> StateDictionary() { Dictionary <string, Contact> stateDictionary = new Dictionary <string, Contact>(); Dictionary <string, AddressBook> .Enumerator enumerator = collectionAddressBook.GetEnumerator(); while (enumerator.MoveNext()) { AddressBook searchAddressBook = enumerator.Current.Value; HashSet <Contact> listOfAddressBook = searchAddressBook.GetAddressBook(); HashSet <Contact> .Enumerator enumerator1 = listOfAddressBook.GetEnumerator(); while (enumerator1.MoveNext()) { Contact c = enumerator1.Current; stateDictionary.Add(enumerator1.Current.state, c); } } return(stateDictionary); }
public string[] SearchByState(string searchKey) { int countOfList = 0; string[] listOfSearchPersonsByState = new string[] { }; Dictionary <string, AddressBook> .Enumerator enumerator = collectionAddressBook.GetEnumerator(); while (enumerator.MoveNext()) { AddressBook searchAddressBook = enumerator.Current.Value; HashSet <Contact> listOfSearch = searchAddressBook.GetAddressBook(); foreach (Contact i in listOfSearch) { if (i.city == searchKey) { listOfSearchPersonsByState[countOfList++] = i.firstName; } } } return(listOfSearchPersonsByState); }