Advertisement
peterbodlev

TestClass_Student

Jul 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace LiveDemo
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<Student, string> university = new Dictionary<Student, string>();
  12.  
  13.             string input = Console.ReadLine();
  14.  
  15.             while (input != "end")
  16.             {
  17.                 string[] inputArr = input.Split();
  18.  
  19.                 string name = inputArr[0];
  20.                 string surname = inputArr[1];
  21.  
  22.                 Student student = new Student(name, surname);
  23.  
  24.                 if (university.ContainsKey(student) == false)
  25.                 {
  26.                     university.Add(student, "Bach ");
  27.                 }
  28.                 else
  29.                 {
  30.  
  31.                     university[student] += "Master";
  32.  
  33.                 }
  34.  
  35.                 input = Console.ReadLine();
  36.             }
  37.            
  38.  
  39.             foreach (var stud in university)
  40.             {
  41.                 Console.WriteLine($"{stud.Key.Name} {stud.Key.Surname} ---- {stud.Value}");
  42.             }
  43.  
  44.             Console.WriteLine(Student.Years);
  45.         }
  46.     }
  47.     class Student
  48.     {
  49.         public string Name { get; set; }
  50.         public string Surname { get; set; }
  51.  
  52.         public Student(string name)
  53.         {
  54.             this.Name = name;
  55.         }
  56.  
  57.         public Student(string name, string surname)
  58.         {
  59.             this.Name = name;
  60.             this.Surname = surname;
  61.         }
  62.  
  63.         public static int Years
  64.         {
  65.             get
  66.             {
  67.                 return 20;
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement