Advertisement
Macrovision

Finding Student Score

Aug 15th, 2022 (edited)
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | Software | 0 0
  1. public class Student
  2.     {
  3.        public List<int> Score { get; set; }
  4.        public string Name { get; set; }
  5.     }
  6.  
  7. var students=new List<Student>
  8.         {
  9.            new Student {Name= "Jessi", Score= new List<int> {97, 72, 81, 60}},
  10.            new Student {Name= "Jolle", Score= new List<int> {75, 84, 91, 39}},
  11.            new Student {Name= "Penton",Score= new List<int> {88, 94, 65, 85}},
  12.            new Student {Name= "Garcia",Score= new List<int> {97, 89, 85, 82}},
  13.            new Student {Name= "Beebe", Score= new List<int> {35, 72, 88, 70}}
  14.         };
  15.  
  16. Console.WriteLine(" Type student name !");
  17. Console.WriteLine();
  18. while (true)
  19. {
  20.        var IName = Console.ReadLine();
  21.    
  22.      
  23.        double cont = 0;
  24.        var score = students.Where(n => n.Name == IName ).Select(p => p.Score).FirstOrDefault();
  25.        
  26.     if (score == null)
  27.     {
  28.         Console.WriteLine("This Name does not Present in the collection.");
  29.     }
  30.     else
  31.     {
  32.         foreach (var i in score)
  33.         {
  34.             cont += i;
  35.             Console.Write(" "+i+" ");
  36.         }
  37.         Console.WriteLine( $" \n"+cont / 4);
  38.         Console.WriteLine();
  39.     }
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement