public void AddContactToBook() { Console.WriteLine("Add new contact"); string[] detailsOfPerson; //enter details from user Console.WriteLine("Enter the following details seperated by comma"); Console.WriteLine("First Name, Last Name, Address, City, State, ZipCode, Phone Number, Email ID"); detailsOfPerson = Console.ReadLine().Split(","); PersonContactDetails personContactDetails = new PersonContactDetails(detailsOfPerson[0], detailsOfPerson[1], detailsOfPerson[2], detailsOfPerson[3], detailsOfPerson[4], detailsOfPerson[5], detailsOfPerson[6], detailsOfPerson[7]); set.Add(personContactDetails); string path = @"C:\Users\USER\source\repos\Address_Book_Problem\Address_Book_Problem\PersonInput.txt"; if (File.Exists(path)) { using (StreamWriter writer = File.AppendText(path)) { writer.WriteLine(personContactDetails.firstName + " " + personContactDetails.lastName + " " + personContactDetails.address + " " + personContactDetails.city + " " + personContactDetails.state + " " + personContactDetails.zipCode + " " + personContactDetails.phoneNumber + " " + personContactDetails.emailID); writer.Close(); } } else { Console.WriteLine("No such file exists"); } Console.WriteLine("Contact added"); }
public Dictionary <string, PersonContactDetails> StateDictionaryCollection() { Dictionary <string, PersonContactDetails> stateDictionary = new Dictionary <string, PersonContactDetails>(); Dictionary <string, AddressBookMain> .Enumerator enumerator = multipleAddressBooks.GetEnumerator(); while (enumerator.MoveNext()) { AddressBookMain searchAddressBook = enumerator.Current.Value; HashSet <PersonContactDetails> addressBook = searchAddressBook.GetAddressBook(); HashSet <PersonContactDetails> .Enumerator enumerator1 = addressBook.GetEnumerator(); while (enumerator1.MoveNext()) { PersonContactDetails c = enumerator1.Current; stateDictionary.Add(enumerator1.Current.state, c); } } return(stateDictionary); }