/// <summary> /// AddContact method is used to add contacts to the list /// </summary> public void AddContact() { bool flag = true; while (flag) { Person_Details person = new Person_Details(); Console.WriteLine("\nEnter First Name"); person.FirstName = Console.ReadLine(); Console.WriteLine("Enter last name"); person.LastName = Console.ReadLine(); Console.WriteLine("Enter address"); person.Address = Console.ReadLine(); Console.WriteLine("Enter city"); person.City = Console.ReadLine(); Console.WriteLine("Enter state"); person.State = Console.ReadLine(); Console.WriteLine("Enter Zip Code"); person.ZipCode = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter phoneNumber"); int phoneNumber = (int)Convert.ToInt64(Console.ReadLine()); foreach (Person_Details personal_Details in addressBook.FindAll(e => e.PhoneNumber == phoneNumber)) { Console.WriteLine("You entered Duplicate Phone Number..."); return; } person.PhoneNumber = phoneNumber; Console.WriteLine("Enter EmailID"); person.EmailId = Console.ReadLine(); this.addressBook.Add(person); Console.WriteLine("Do you want to continue YES/NO"); string input = Console.ReadLine(); if (input == "Y" || input == "YES" || input == "y" || input == "yes") { DisplayMenu(); } else if (input == "N" || input == "NO" || input == "n" || input == "no") { flag = false; Console.WriteLine("Thank you"); } } }
public int Compare(Person_Details x, Person_Details y) { Console.WriteLine("Enter choice for sorting:"); Console.WriteLine("1. FirstName 2. City 3. State 4. ZipCode"); String choice = Console.ReadLine(); int choice1 = Convert.ToInt32(choice); switch (choice1) { case 1: return(x.FirstName.CompareTo(y.FirstName)); case 2: return(x.City.CompareTo(y.City)); case 3: return(x.State.CompareTo(y.State)); case 4: return(x.ZipCode.CompareTo(y.ZipCode)); } return(0); }