Advertisement
Guest User

Untitled

a guest
Mar 7th, 2017
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 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 ConsoleApplication1
  8. {
  9. class Person
  10. {
  11. public int id;
  12. public string name;
  13. public string email;
  14. public double weight;
  15. public int age;
  16.  
  17. public Person(int id, string name, string email, double weight, int age)
  18. {
  19. this.id = id;
  20. this.name = name;
  21. this.email = email;
  22. this.weight = weight;
  23. this.age = age;
  24. }
  25.  
  26. public override string ToString()
  27. {
  28. return this.id + "\t" + this.name + "\t" + this.email;
  29. }
  30. }
  31.  
  32. class Program
  33. {
  34. static void Main(string[] args)
  35. {
  36.  
  37. List<Person> people = new List<Person>();
  38.  
  39. int id = -1;
  40. people.Add(new Person(++id, "Bob", "bob@gmail.com", 76.31, 12));
  41. people.Add(new Person(++id, "Lajos", "lajcsi@freemail.hu", 31, 8));
  42. people.Add(new Person(++id, "Tarzan", "i.tarzan@haubsburg.hu", 45.32, 18));
  43. people.Add(new Person(++id, "Juli", "julcsi@gmail.com", 42.234, 14));
  44. people.Add(new Person(++id, "Zsolt", "zsolt@freemail.hu", 92, 15));
  45. people.Add(new Person(++id, "Évi", "evi@gmail.com", 38, 17));
  46. people.Add(new Person(++id, "Másik Évi", "evi2@gmail.com", 47.63, 18));
  47. people.Add(new Person(++id, "Harmadik Évi", "evi.3@gmail.com", 18.1, 21));
  48. people.Add(new Person(++id, "Büdöske", "ciccaa@freemail.hu", 63, 25));
  49. people.Add(new Person(++id, "Pilács", "pilacs@freemail.hu", 65.191, 14));
  50. people.Add(new Person(++id, "Elek", "elek@citromail.hu", 71, 18));
  51. people.Add(new Person(++id, "Péló", "pelo@gmail.com", 81.58, 42));
  52. people.Add(new Person(++id, "Tibor", "tibi@freemail.hu", 12, 31));
  53. people.Add(new Person(++id, "Qulomb", "qlom@gmail.com", 54, 17));
  54. people.Add(new Person(++id, "Xxxxszavéér", "xxx@gmail.com", 69, 69));
  55. people.Add(new Person(++id, "Dénes", "denes@gmail.com", 54, 54));
  56.  
  57. // C# Linq:
  58.  
  59. var groupByEmail = from person in people
  60. orderby person.name
  61. group person by person.email.Split(new char[] {'@'})[1] into personGroup
  62. select new { Email = personGroup.Key, Person = personGroup };
  63.  
  64. foreach (var person in groupByEmail)
  65. Console.WriteLine(person.Email + "\t\n\t" + string.Join("\n\t", person.Person));
  66.  
  67. Console.Read();
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement