Advertisement
Aborigenius

SearchString

Jun 20th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 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 PhoneBook
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] phoneNumbers = Console.ReadLine().Split(' ');
  14.             string[] names = Console.ReadLine().Split(' ');
  15.  
  16.            Search(names, phoneNumbers);
  17.         }
  18.         static string Search(string[] names, string[] phoneNumbers)
  19.         {
  20.             string commands = String.Empty;
  21.             string result = String.Empty;
  22.             do
  23.             {
  24.                 commands = Console.ReadLine();
  25.                 foreach (string x in names)
  26.                 {
  27.                     if (x.Equals(commands))
  28.                     {
  29.                         int index1 = Array.IndexOf(names, x);
  30.                         result = $"{names[index1]} -> {phoneNumbers[index1]}";
  31.                         Console.WriteLine(result);
  32.                     }
  33.                     else
  34.                     {
  35.                         continue;
  36.                     }
  37.                 }
  38.             } while (commands != "done");
  39.             return result;
  40.         }
  41.     }
  42. }
  43. /*          string search = Console.ReadLine();
  44.             search = Array.FindAll(names, s => s.Equals(search));
  45.             return search;
  46. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement