Advertisement
Guest User

Contacts

a guest
May 30th, 2018
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 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 Emails
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             var contacts = new List<string>();
  14.             contacts.Add("Паша:p@p.ru");
  15.             contacts.Add("Паша:pavel.egorov@urfu.ru");
  16.             contacts.Add("Маша:masha@mail.ru");
  17.             contacts.Add("Маша:maha@gmail.com");
  18.             contacts.Add("Юля:belekhova@gmail.com");
  19.             contacts.Add("Ваня:v@mail.ru");
  20.             contacts.Add("Вася:vasiliy@gmail.com");
  21.             contacts.Add("Ваня:ivan@grozniy.ru");
  22.             contacts.Add("Ваня:vanechka@domain.com");
  23.             OptimizeContacts(contacts);
  24.  
  25.         }
  26.  
  27.         private static Dictionary<string, List<string>> OptimizeContacts(List<string> contacts)
  28.         {
  29.             var dictionary = new Dictionary<string, List<string>>();
  30.             var names = contacts.Select(n => n.Split(':'));
  31.             var list = new List<string>();
  32.             foreach (var e in names)
  33.             {
  34.                 var key = e[0].Substring(0, 2);
  35.                 var names1 = string.Join(":", e);
  36.                 if (!dictionary.ContainsKey(key))
  37.                     dictionary[key] = list.Add(names1); //Не удается неявно преобразовать тип "void" в                              //"System.Collections.Generic.List<string>".
  38.                 dictionary[key] = list.Add(names1);
  39.             }
  40.                 return dictionary;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement