C# Linq orderby example

The default sort is ascending order. You can alter the order by using the “ascending” and “descending”
keywords, and further change the order by specifying more than one field to sort
by.

List<Book> ListOfBooks = new List<Book>()
{
    new Book {name = "DaVinci Code"    , owner = "Alex" , date = 2002},
    new Book {name = "Angels and Demons", owner = "Jeff" , date = 2005},
    new Book {name = "The Last Mughal", owner = "Danny", date = 2001},
};
IEnumerable<Book> QueryResult = from Book in ListOfBooks
				orderby Book.name  descending
                                select Book;
Share Article/Example:
  • Facebook
  • Twitter
  • del.icio.us
  • Digg
  • DotNetKicks
  • DZone