Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Emails
- {
- class Program
- {
- static void Main()
- {
- var contacts = new List<string>();
- contacts.Add("Паша:p@p.ru");
- contacts.Add("Паша:pavel.egorov@urfu.ru");
- contacts.Add("Маша:masha@mail.ru");
- contacts.Add("Маша:maha@gmail.com");
- contacts.Add("Юля:belekhova@gmail.com");
- contacts.Add("Ваня:v@mail.ru");
- contacts.Add("Вася:vasiliy@gmail.com");
- contacts.Add("Ваня:ivan@grozniy.ru");
- contacts.Add("Ваня:vanechka@domain.com");
- OptimizeContacts(contacts);
- }
- private static Dictionary<string, List<string>> OptimizeContacts(List<string> contacts)
- {
- var dictionary = new Dictionary<string, List<string>>();
- var names = contacts.Select(n => n.Split(':'));
- var list = new List<string>();
- foreach (var e in names)
- {
- var key = e[0].Substring(0, 2);
- var names1 = string.Join(":", e);
- if (!dictionary.ContainsKey(key))
- dictionary[key] = list.Add(names1); //Не удается неявно преобразовать тип "void" в //"System.Collections.Generic.List<string>".
- dictionary[key] = list.Add(names1);
- }
- return dictionary;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement