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 ConsoleApplication1
- {
- class Person
- {
- public int id;
- public string name;
- public string email;
- public double weight;
- public int age;
- public Person(int id, string name, string email, double weight, int age)
- {
- this.id = id;
- this.name = name;
- this.email = email;
- this.weight = weight;
- this.age = age;
- }
- public override string ToString()
- {
- return this.id + "\t" + this.name + "\t" + this.email;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Person> people = new List<Person>();
- int id = -1;
- people.Add(new Person(++id, "Bob", "bob@gmail.com", 76.31, 12));
- people.Add(new Person(++id, "Lajos", "lajcsi@freemail.hu", 31, 8));
- people.Add(new Person(++id, "Tarzan", "i.tarzan@haubsburg.hu", 45.32, 18));
- people.Add(new Person(++id, "Juli", "julcsi@gmail.com", 42.234, 14));
- people.Add(new Person(++id, "Zsolt", "zsolt@freemail.hu", 92, 15));
- people.Add(new Person(++id, "Évi", "evi@gmail.com", 38, 17));
- people.Add(new Person(++id, "Másik Évi", "evi2@gmail.com", 47.63, 18));
- people.Add(new Person(++id, "Harmadik Évi", "evi.3@gmail.com", 18.1, 21));
- people.Add(new Person(++id, "Büdöske", "ciccaa@freemail.hu", 63, 25));
- people.Add(new Person(++id, "Pilács", "pilacs@freemail.hu", 65.191, 14));
- people.Add(new Person(++id, "Elek", "elek@citromail.hu", 71, 18));
- people.Add(new Person(++id, "Péló", "pelo@gmail.com", 81.58, 42));
- people.Add(new Person(++id, "Tibor", "tibi@freemail.hu", 12, 31));
- people.Add(new Person(++id, "Qulomb", "qlom@gmail.com", 54, 17));
- people.Add(new Person(++id, "Xxxxszavéér", "xxx@gmail.com", 69, 69));
- people.Add(new Person(++id, "Dénes", "denes@gmail.com", 54, 54));
- // C# Linq:
- var groupByEmail = from person in people
- orderby person.name
- group person by person.email.Split(new char[] {'@'})[1] into personGroup
- select new { Email = personGroup.Key, Person = personGroup };
- foreach (var person in groupByEmail)
- Console.WriteLine(person.Email + "\t\n\t" + string.Join("\n\t", person.Person));
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement