Advertisement
diyanborisov

RemoveNames

Dec 28th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 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.  
  8. class RemoveNames
  9. {
  10.     static void Main()
  11.     {
  12.         string input = string.Empty;
  13.         List<string> namesFirst = new List<string>();
  14.         List<string> namesSecond = new List<string>();
  15.         bool check = true;
  16.  
  17.         NamesInput(input,check,namesFirst,namesSecond);
  18.  
  19.         RemoveListElements(namesFirst, namesSecond);
  20.  
  21.         Console.WriteLine("\n"+String.Join(" ", namesFirst));
  22.     }
  23.  
  24.     static void NamesInput(string input,bool check,List<string> namesFirst,List<string> namesSecond)
  25.     {
  26.         Console.WriteLine("Please input names in first list:\n(Enter \"end\" or \"END\" to finish this operation.)\n");
  27.         while (input != "end" || input != "END")
  28.         {
  29.             input = Console.ReadLine();
  30.             if (input == "end" || input == "END")
  31.             {
  32.                 break;
  33.             }
  34.            
  35.             namesFirst.Add(input);
  36.         }
  37.  
  38.         Console.WriteLine("Please input names in second list:\n(Enter \"end\" or \"END\" to finish this operation.)\n");
  39.         while (input != "end" || input != "END")
  40.         {
  41.             input = Console.ReadLine();
  42.             if (input == "end" || input == "END")
  43.             {
  44.                 break;
  45.             }
  46.             namesSecond.Add(input);
  47.         }
  48.     }
  49.     static void RemoveListElements(List<string> namesFirst, List<string> namesSecond)
  50.     {
  51.         for (int i = 0; i < namesSecond.Count; i++)
  52.         {
  53.             for (int x = 0; x < namesFirst.Count; x++)
  54.             {
  55.                 if (namesSecond[i] == namesFirst[x])
  56.                 {
  57.                     namesFirst.Remove(namesSecond[i]);
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement