Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_text/tests/detect_corpus/csharp/properties_linq.txt

1.8 KiB, 1 run

created by r1870400018:11970, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1using System;
2using System.Collections.Generic;
3using System.Linq;
4
5namespace Annealer.Examples
6{
7 public class Student
8 {
9 public string Name { get; set; } = "";
10 public int Grade { get; set; }
11 public double Score { get; set; }
12
13 public bool IsPassing => Score >= 60.0;
14 }
15
16 public class Classroom
17 {
18 private readonly List<Student> _students = new();
19
20 public int Count => _students.Count;
21
22 public void Add(Student student)
23 {
24 _students.Add(student);
25 }
26
27 public IEnumerable<Student> TopPerformers(int n)
28 {
29 return _students
30 .OrderByDescending(s => s.Score)
31 .Take(n);
32 }
33
34 public double AverageScore()
35 {
36 return _students.Average(s => s.Score);
37 }
38
39 public Dictionary<int, List<Student>> GroupByGrade()
40 {
41 return _students
42 .GroupBy(s => s.Grade)
43 .ToDictionary(g => g.Key, g => g.ToList());
44 }
45
46 public IEnumerable<string> PassingNames()
47 {
48 return _students
49 .Where(s => s.IsPassing)
50 .Select(s => s.Name)
51 .OrderBy(n => n);
52 }
53 }
54
55 class Program
56 {
57 static void Main()
58 {
59 var classroom = new Classroom();
60 classroom.Add(new Student { Name = "Alice", Grade = 12, Score = 92.5 });
61 classroom.Add(new Student { Name = "Bob", Grade = 11, Score = 55.0 });
62 classroom.Add(new Student { Name = "Charlie", Grade = 12, Score = 87.3 });
63
64 Console.WriteLine($"average: {classroom.AverageScore():F1}");
65
66 foreach (var name in classroom.PassingNames())
67 {
68 Console.WriteLine($" passing: {name}");
69 }
70 }
71 }
72}