ThenBy and ThenByDescending example in LINQ

var query13 = ProductList.OrderBy(p = > p.CategoryID)
                   .ThenByDescending(p = > p.UnitPrice)
                   .ThenBy(p = > p.ProductName);
 
query13 = from p in ProductList
              orderby p.CategoryID, p.UnitPrice descending, p.ProductName
              select p;
 
foreach (var p in query13)
           sbResult.Append(String.Format(“CategoryID = {0}, UnitPrice = {1:c}, “ +
           Name = {2}\r\n”, p.CategoryID, p.UnitPrice, p.ProductName));

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.