C#
Создаем новое консольное приложение C# и пишем:
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1
{
class Human
{
public long Id { get; set; }
public string Name { get; set; }
public string Age { get; set; }
public string Height { get; set; }
}
class Program
{
static void Main(string[] args)
{
// array Human
Human[] humans =
{
new Human() {Id = 1, Name = "Vasia", Age = "23year", Height = "178cm"},
new Human() {Id = 2, Name = "Vasia", Age = "40year", Height = "172cm"},
new Human() {Id = 3, Name = "Petia", Age = "23year", Height = "122cm"},
new Human() {Id = 4, Name = "Vasia", Age = "23year", Height = "122cm"},
new Human() {Id = 5, Name = "Vasia", Age = "23year", Height = "122cm"},
new Human() {Id = 6, Name = "Vasia", Age = "36year", Height = "210cm"},
};
// group by 'Name'
IEnumerable< IGrouping<string, Human> > result = humans.GroupBy(g1 => g1.Name);
// enumerate each item in result
foreach (IGrouping<string, Human> groupItem in result)
{
// display key
Console.WriteLine(" Key = " + groupItem.Key);
// enumerate each Human for this key
foreach (Human human in groupItem)
{
// display Human
Console.WriteLine("Id=" + human.Id +
" Name=" + human.Name +
" Age=" + human.Age +
" Height=" + human.Height);
}
}
}
}
}