var query = from emp in employees
orderby emp.Nationality,
emp.LastName descending,
emp.FirstName descending
select emp;
foreach( var item in query ) {
Console.WriteLine( "{0},\t{1},\t{2}",
item.LastName,
item.FirstName,
item.Nationality );
}
}
}
Notice that since the select clause simply returns the range variable, this whole query expres-
sion is nothing more than a sort operation. But it sure is a convenient way to sort things in C#. In
this example, I sort first by Nationality in ascending order, then the second expression in the
orderby clause sorts the results of each nationality group by LastName in descending order, and
finally, each of those groups is sorted by FirstName in descending order.
At compile time, the compiler translates the first expression ...