Advertisement
PcTechOfficial

Basic Phonebook by Print101

May 25th, 2020
14,756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography.X509Certificates;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace PhoneBookExample
  9. {
  10.     class Program
  11.     {
  12.         public static List<string> PhoneBookPrev = new List<string>();
  13.         String[] PhoneBook = PhoneBookPrev.ToArray();
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             string Input;
  18.             Console.Title = "PhoneBookV1";
  19.  
  20.             while (true)
  21.             {
  22.                 Console.WriteLine("Get or Set?");
  23.                 Input = Console.ReadLine();
  24.  
  25.                 if (Input == "Get")
  26.                 {
  27.                     Get();
  28.                 }
  29.                 else if (Input == "Set")
  30.                 {
  31.                     Set();
  32.                 }
  33.                 else
  34.                 {
  35.                     Console.WriteLine("Invalid Decision.");
  36.                 }
  37.             }
  38.         }
  39.  
  40.         public static void Get()
  41.         {
  42.             Console.Clear();
  43.             Console.WriteLine("-----------------------------------------------");
  44.             Console.WriteLine("Getting All Contacts... Please be Patient.");
  45.             Console.WriteLine("-----------------------------------------------");
  46.             System.Threading.Thread.Sleep(5000);
  47.             Console.Clear();
  48.  
  49.  
  50.             if (PhoneBookPrev.Count <= 0)
  51.             {
  52.                 Console.WriteLine("No Contacts Found.");
  53.                 System.Threading.Thread.Sleep(5000);
  54.                 Console.Clear();
  55.             }
  56.             else if (PhoneBookPrev.Count > 0)
  57.             {
  58.                 Console.WriteLine("A Total of " + PhoneBookPrev.Count + " Contacts were Found.");
  59.                 Console.WriteLine("-------------------------------------------------------------------");
  60.                 foreach (string contactInfo in PhoneBookPrev)
  61.                 {
  62.                     Console.WriteLine(contactInfo);
  63.                 }
  64.                 Console.WriteLine("-------------------------------------------------------------------");
  65.             }
  66.         }
  67.  
  68.         public static void Set()
  69.         {
  70.             string info;
  71.             Console.WriteLine("-- Set a new PhoneBook --");
  72.             Console.WriteLine();
  73.             Console.Write("Enter Name: ");
  74.             info = Console.ReadLine();
  75.             try
  76.             {
  77.                 PhoneBookPrev.Add(info);
  78.                 Console.Write("Contact " + info + " has been successfully added to your contacts.");
  79.             }
  80.             catch (Exception)
  81.             {
  82.                 Console.Write("There was an Error whilst trying to add that Contact Information!");
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement