How can I arrange students in descending order? Here is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Student.Models;
namespace Student.Controllers {
public class StudentController : Controller
{
//
// GET: /Student/
private IStudentRepository _repository;
public StudentController() : this(new StudentRepository())
{
}
public StudentController(IStudentRepository repository)
{
_repository = repository;
}
public ActionResult Index()
{
return View(_repository.ListAll());
}
}
Replace Name with the property that you wanna order by
I strongley recommend taking this as an opportunity to look at all the extension methods that linq provide (e.g. OrderBy, Where, Select, .. etc), the more you learn about the linq API the easier your life will get working with Collections