Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Student
- {
- public string Name { get; }
- public string Gender { get; }
- public int Salary { get; }
- public Student(string name, string gender, int salary)
- {
- Name = name;
- Gender = gender;
- Salary = salary;
- }
- }
- public class Program
- {
- private static string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- public static void Main(string[] args)
- {
- string path = desktopPath + @"\Something.txt";
- List<Student> students = new List<Student>();
- foreach (string line in File.ReadAllLines(path))
- {
- string[] columns = line.Split(' ');
- students.Add(new Student(columns[0], columns[1], int.Parse(columns[2])));
- }
- students.Sort((previous, next) => previous.Salary.CompareTo(next.Salary));
- int count = students.Count < 5 ? students.Count : 5;
- for (int i = 0; i < count; i++)
- Console.WriteLine(students[i].Name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment