C# Linq grouping example

LINQ also allows grouping the query result by the value of a specific property as shown in this example:

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