How to use LINQ orderby clause to sort results in C#

Sometimes Web developers have to sort the returned data. The LINQ orderby clause sorts the elements in the returned sequence according to the default comparer for the type being sorted. For example, the following query can be extended to sort the results based on the FirstName property. Because FirstName is a string, the default comparer performs an alphabetical sort from A to Z:

var queryNewYorkClients =

from client in clients

where client.City == “New York”

orderby client.FirstName ascending

select client;

 

Web developers can order the results in reverse order, from Z to A, by using the orderby…descending clause.

If you want to host ASP.NET 4 application then you will need ASP.NET 4.0 hosting provider which supports .NET 4.0 Framework.