-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
42 lines (39 loc) · 1.5 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace NewLINQMethodsCsharp13
{
record Student (string Name, string Score);
public class Program
{
public static void Main(string[] args)
{
Student[] students = [
new("Alice", "A"),
new("Bob", "B"),
new("Charlie", "C"),
new("David", "B"),
new("Eve", "A")
];
Console.WriteLine("----------Index-----------");
foreach (var (index, student) in students.Index())
{
Console.WriteLine($"Student {index}: {student.Name}");
}
Console.WriteLine();
Console.WriteLine("----------CountBy-----------");
Console.WriteLine();
foreach (var (score, count) in students.CountBy(student => student.Score))
{
Console.WriteLine($"Students with a {score}-score: {count}");
}
Console.WriteLine();
Console.WriteLine("----------AggregateBy-----------");
Console.WriteLine();
foreach (var (score, studentGroup) in students.AggregateBy(
keySelector => keySelector.Score,
seed: new List<Student>(),
func: (group, student)=> [..group, student]))
{
Console.WriteLine($"Students with a {score}-score: {string.Join(", ", studentGroup)}");
}
}
}
}