NarekNavoyan

23-2

May 25th, 2022
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. public class Student
  2. {
  3.     public string Name { get; }
  4.     public string Gender { get; }
  5.     public int Salary { get; }
  6.  
  7.     public Student(string name, string gender, int salary)
  8.     {
  9.         Name = name;
  10.         Gender = gender;
  11.         Salary = salary;
  12.     }
  13. }
  14.  
  15. public class Program
  16. {
  17.     private static string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  18.    
  19.     public static void Main(string[] args)
  20.     {
  21.         string path = desktopPath + @"\Something.txt";
  22.  
  23.         List<Student> students = new List<Student>();
  24.         foreach (string line in File.ReadAllLines(path))
  25.         {
  26.             string[] columns = line.Split(' ');
  27.             students.Add(new Student(columns[0], columns[1], int.Parse(columns[2])));
  28.         }
  29.         students.Sort((previous, next) => previous.Salary.CompareTo(next.Salary));
  30.  
  31.         int count = students.Count < 5 ? students.Count : 5;
  32.         for (int i = 0; i < count; i++)
  33.             Console.WriteLine(students[i].Name);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment