Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace KsiazkaTele2
  8. {
  9.     public class Person
  10.     {
  11.         public string FirstName { get; set; }
  12.         public string LastName { get; set; }
  13.         public string PhoneNumber { get; set; }
  14.         public string[] Addresses { get; set; }
  15.  
  16.         public static List<Person> People = new List<Person>();
  17.  
  18.         public static void AddPerson()
  19.         {
  20.             Person person = new Person();
  21.  
  22.             Console.Write("Enter First Name: ");
  23.             person.FirstName = Console.ReadLine();
  24.  
  25.             Console.Write("Enter Last Name: ");
  26.             person.LastName = Console.ReadLine();
  27.  
  28.             Console.Write("Enter Phone Number: ");
  29.             person.PhoneNumber = Console.ReadLine();
  30.  
  31.             Console.Write("Enter Address 1: ");
  32.             string[] addresses = new string[2];
  33.             addresses[0] = Console.ReadLine();
  34.             Console.Write("Enter Address 2 (Optional): ");
  35.             addresses[1] = Console.ReadLine();
  36.             person.Addresses = addresses;
  37.  
  38.             People.Add(person);
  39.         }
  40.  
  41.         public static void PrintPerson(Person person)
  42.         {
  43.             Console.WriteLine("First Name: " + person.FirstName);
  44.             Console.WriteLine("Last Name: " + person.LastName);
  45.             Console.WriteLine("Phone Number: " + person.PhoneNumber);
  46.             Console.WriteLine("Address 1: " + person.Addresses[0]);
  47.             Console.WriteLine("Address 2: " + person.Addresses[1]);
  48.             Console.WriteLine("-------------------------------------------");
  49.         }
  50.  
  51.         public static void ListPeople()
  52.         {
  53.             if (People.Count == 0)
  54.             {
  55.                 Console.WriteLine("Your address book is empty. Press any key to continue.");
  56.                 Console.ReadKey();
  57.                 return;
  58.             }
  59.             Console.WriteLine("Here are the current people in your address book:\n");
  60.             foreach (var person in People)
  61.             {
  62.                 PrintPerson(person);
  63.             }
  64.             Console.WriteLine("\nPress any key to continue.");
  65.             Console.ReadKey();
  66.         }
  67.  
  68.  
  69.     }
  70. }
  71.  
  72. =================================================================================================================================
  73.  
  74. using System;
  75. using System.Collections.Generic;
  76. using System.Linq;
  77. using System.Text;
  78. using System.Threading.Tasks;
  79.  
  80. namespace KsiazkaTele2
  81. {
  82.     class Program
  83.     {
  84.         static void Main(string[] args)
  85.         {
  86.             Person p1 = new Person();
  87.  
  88.             string command = "";
  89.             while (command != "exit")
  90.             {
  91.                 Console.Clear();
  92.                 Console.WriteLine("Please enter a command: ");
  93.                 command = Console.ReadLine().ToLower();
  94.                 switch (command)
  95.                 {
  96.                     case "add":
  97.                         Person.AddPerson();
  98.                         break;
  99.                     //case "remove":
  100.                     //    Person.RemovePerson();
  101.                     //    break;
  102.                     case "list":
  103.                         Person.ListPeople();
  104.                         break;
  105.                 }
  106.             }
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement