本文介绍了我如何只查看成绩最高的学生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class Program
    {
        static void Main(string[] args)
        {
            string surname;
            int score;
            int numRecords = 0;
            Console.WriteLine("How many students?");
            if (int.TryParse(Console.ReadLine(), out numRecords))
            {
                List<Student> lstStudent = new List<Student>();
                for (var i = 1; i <= numRecords; i++)
                {
                    Student student = new Student();
                    Console.WriteLine();
                    Console.Write("Enter Name:");
                    student.Name = Console.ReadLine();
                    Console.Write("Enter Surname:");
                    student.SurName = Console.ReadLine();
                    Console.Write("Enter Score:");
                    student.Score = int.Parse(Console.ReadLine());
                    lstStudent.Add(student);
                    Console.WriteLine();
                }
                lstStudent = (List<Student>)lstStudent.OrderByDescending(x => x.Score).ToList(); 
                

                for (int i = 0; i < lstStudent.Count; i++)
                {
                    Console.WriteLine("{1},{2},{3}", (i + 1).ToString(), lstStudent[i].Name, lstStudent[i].SurName, lstStudent[i].Score.ToString());
                }
            }
            Console.ReadLine();
        }
    }

    public class Student
    {
        public string Name { get; set; }
        public string SurName { get; set; }
        public Int32 Score { get; set; }
    }
}



上面的代码使我可以输入和显示所有学生成绩,但是现在我希望仅查看成绩最高的学生.任何帮助将不胜感激.



The code above enables me input and display all the student marks, but now l want to be able to view only the students with the top marks. Any help would be appreciated.

推荐答案


这篇关于我如何只查看成绩最高的学生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 09:15