Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
  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.
Posted

1 solution

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.
 
Share this answer
 
Comments
kills 26-Nov-12 1:26am    
is there a way of doing it without the need to process through database query? l want to use console app to do everything.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900