SQLに類似。
成果物
情報源
コード
class Human { public string Name { get; } public int Age { get; } public Human(string name, int age) => (Name, Age) = (name, age); } class Main { public void Run() { List<Human> humans = CreateHumans(); Show(Query(humans)); } private List<Human> CreateHumans() { return new List<Human> { new Human("A", 0), new Human("B", 1), new Human("A", 2), new Human("B", 3), new Human("A", 4), new Human("B", 5), }; } private IEnumerable<dynamic> Query(in List<Human> humans) { return from h in humans group h by h.Name into g select new { Name = g.Key, MaxAge = (from h2 in g select h2.Age).Max(), }; } private void Show(in IEnumerable<dynamic> groups) { foreach (var g in groups) { Console.WriteLine($"Name={g.Name}, MaxAge={g.MaxAge}"); } } }
Name=A, MaxAge=4 Name=B, MaxAge=5
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13 ※
- bash 4.4.12(1)-release ※
- SQLite 3.29.0 ※
- C# dotnet 3.0.100 ※
$ uname -a Linux raspberrypi 4.19.42-v7+ #1218 SMP Tue May 14 00:48:17 BST 2019 armv7l GNU/Linux