SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 114 | Next

Scott Klein

"Professional LINQ"

Select(c => new {
c.FirstName, c.Lastname, c.EmailAddress}
).Where(c => c.FirstName.StartsWith("S"));
Sorting Operators
The sorting operators??”OrderBy, OrderByDescending, ThenBy, ThenByDescending, and
Reverse??”provide the capability to sort the results in an ascending or descending manner.
There are several sorting options that let you apply primary and secondary sorts as well. These
operators are explored in the following sections.
OrderBy
The OrderBy operator sorts the resulting values of the sequence in an ascending order. The following
example shows how to sort a sequence in ascending order:
var query =
from c in contact
where c.FirstName.StartsWith("S")
orderby c.LastName
select new {c.FirstName, c.LastName, c.EmailAddress}
You can also sort the sequence in ascending order by using a comparer. A comparer is an optional value
that is used to compare values. If no comparer is specified, a default is used, which comes from the
IComparer generic interface.
This example could also be written using method syntax as follows:
var query =
contact.


Pages:
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6