Caveman's Blog

My commitment to learning.

Linq: OrderByDescending operator

leave a comment »

OrderByDescending is one of the query operators in linq and can be can be to sort data, objects by descending order. Following is an example of an employee collection that is sorted in descending order using the OrderByDescending operator. The following code snippet illustrated the ordering of the Employee objects in descending order:

 class Program
        static void Main(string[] args)
            List<Employee> EmployeeList = new List<Employee>();
            Employee employee = new Employee();
            employee.ID = 1001;
   = "User 1001";

            employee = new Employee();
            employee.ID = 1007;
   = "User 1007";

            employee = new Employee();
            employee.ID = 1002;
   = "User 1002";

            var sortedEmployeed = EmployeeList.OrderByDescending(i => i.ID);
            foreach (var emp in sortedEmployeed)
                Console.WriteLine("EmployeeID: {0}", emp.ID);


    public class Employee
        public int ID { get; set; }
        public string name { get; set; }

Written by cavemansblog

January 8, 2012 at 1:38 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: