-1

I want to order by descending in List Using Linq.

Here I want to order by isApproved.

List<DoctorViewModel> doctors = new List<DoctorViewModel>();
public class DoctorViewModel
{
    public string Email { get; set; }
    public string Name { get; set; }
    public int isApproved { get; set; }
}
  • 2
    use [OrderByDescending](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.orderbydescending?view=netframework-4.7.2) – styx Jan 23 '19 at 09:30

2 Answers2

1

Just try

doctors = doctors.OrderByDescending(doctor => doctor.isApproved).ToList();
Venkatesh
  • 192
  • 3
  • 15
0

You can use the following query to order by descending by isApproved column doctors.OrderByDescending(d=> d.isApproved).ToList();

Also, if you want to do descending in two level use the following query

doctors.OrderByDescending(d=> d.isApproved).ThenBy(d=> d.Name).ToList();

Let me know if you face any challenge and please mark as answer if it will resolve your problem.

Shyam Sa
  • 331
  • 4
  • 8