我如何只查看成绩最高的学生? [英] How do l view only the students with the top mark?

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

问题描述

  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.

推荐答案

如果通过数据库查询填充学生名单,则应尝试对查询中的最高分进行处理.
只需在查询中使用MAX TOP ORDER BY标记即可按适当的顺序获取数据.
If you populate the student list via a database query, you should try doing processing for top marks in the query.
Just use MAX or TOP in the query or ORDER BY marks to get data in the appropriate order.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆