Aggregation
Aggregate, Average, Count, LongCount, Max, Min, Sum
Conversion
AsEnumerable, Cast, OfType, ToArray, ToDictionary, ToList, ToLookup
Element
ElementAt, ElementAtOrDefault, First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault
ElementAt
ElementAtOrDefault
First (simple)
First (conditional)
FirstOrDefault
Last
LastOrDefault (simple)
LastOrDefault (conditional)
Single
SingleOrDefault
Generation
DefaultIfEmpty, Empty, Range, Repeat
Grouping
GroupBy
Join
GroupJoin, Join
Ordering
OrderBy, OrderByDescending, Reverse, ThenBy, ThenByDescending
OrderBy (simple - numbers)
OrderBy (simple - dates)
OrderBy (simple - objects)
OrderByDescending
Reverse
ThenBy
ThenByDescending
Other
Concat, SequenceEqual, Zip
Partitioning
Skip, SkipWhile, Take, TakeWhile
Projection
Select, SelectMany
Quantifiers
All, Any, Contains
Restriction
Where
Set
Distinct, Except, Intersect, Union
Close
ThenByDescending: Use after earlier sorting, to further sort a collection in descending order.
ThenByDescending: Use after earlier sorting, to further sort a collection in descending order. |
ThenByDescending: Use after earlier sorting, to further sort a collection in descending order. |
This Lambda Expression sample first orders a list of dates by year descending, and then by month descending. |
This Lambda Expression sample first orders a list of dates by year descending, and then by month descending. |
static void Sample_ThenByDescending_Linq() { var dates = new DateTime[] { new DateTime(2015, 3, 1), new DateTime(2014, 7, 1), new DateTime(2013, 5, 1), new DateTime(2015, 1, 1), new DateTime(2015, 7, 1) }; var result = from d in dates orderby d.Year descending, d.Month descending select d; Debug.WriteLine("List of dates first ordered by year descending, and then by month descending:"); foreach (DateTime dt in result) Debug.WriteLine(dt.ToString("yyyy/MM/dd")); }Output:
List of dates first ordered by year descending, and then by month descending: 2015-07-01 2015-03-01 2015-01-01 2014-07-01 2013-05-01
Private Shared Sub Sample_ThenByDescending_Linq() Dim dates = New DateTime() { _ New DateTime(2015, 3, 1), _ New DateTime(2014, 7, 1), _ New DateTime(2013, 5, 1), _ New DateTime(2015, 1, 1), _ New DateTime(2015, 7, 1) } Dim result = From d In dates _ Order By d.Year Descending, d.Month Descending Select d Debug.WriteLine("List of dates first ordered by year descending, and then by month descending:") For Each dt As DateTime In result Debug.WriteLine(dt.ToString("yyyy/MM/dd")) Next End SubOutput:
List of dates first ordered by year descending, and then by month descending: 2015-07-01 2015-03-01 2015-01-01 2014-07-01 2013-05-01
let Sample_ThenByDescending_Linq() = let dates = [|new DateTime(2015, 3, 1); new DateTime(2014, 7, 1); new DateTime(2013, 5, 1); new DateTime(2015, 1, 1); new DateTime(2015, 7, 1)|] let result = query { for d in dates do sortByDescending d.Year thenByDescending d.Month select d } Debug.WriteLine(sprintf "List of dates first ordered by year descending, and then by month descending:"); for dt in result do Debug.WriteLine(dt.ToString("yyyy/MM/dd"))Output:
List of dates first ordered by year descending, and then by month descending: 2015-07-01 2015-03-01 2015-01-01 2014-07-01 2013-05-01
static void Sample_ThenByDescending_Lambda() { var dates = new DateTime[] { new DateTime(2015, 3, 1), new DateTime(2014, 7, 1), new DateTime(2013, 5, 1), new DateTime(2015, 1, 1), new DateTime(2015, 7, 1) }; var result = dates.OrderByDescending(d => d.Year).ThenByDescending(d => d.Month); Debug.WriteLine("List of dates first ordered by year descending, and then by month descending:"); foreach (DateTime dt in result) Debug.WriteLine(dt.ToString("yyyy/MM/dd")); }Output:
List of dates first ordered by year descending, and then by month descending: 2015-07-01 2015-03-01 2015-01-01 2014-07-01 2013-05-01
Private Shared Sub Sample_ThenByDescending_Lambda() Dim dates = New DateTime() { _ New DateTime(2015, 3, 1), _ New DateTime(2014, 7, 1), _ New DateTime(2013, 5, 1), _ New DateTime(2015, 1, 1), _ New DateTime(2015, 7, 1) } Dim result = dates.OrderByDescending(Function(d) d.Year).ThenByDescending(Function(d) d.Month) Debug.WriteLine("List of dates first ordered by year descending, and then by month descending:") For Each dt As DateTime In result Debug.WriteLine(dt.ToString("yyyy/MM/dd")) Next End SubOutput:
List of dates first ordered by year descending, and then by month descending: 2015-07-01 2015-03-01 2015-01-01 2014-07-01 2013-05-01
let Sample_ThenByDescending_Lambda() = let dates = [|new DateTime(2015, 3, 1); new DateTime(2014, 7, 1); new DateTime(2013, 5, 1); new DateTime(2015, 1, 1); new DateTime(2015, 7, 1)|] let result = dates.OrderByDescending(fun d -> d.Year).ThenByDescending(fun d -> d.Month) Debug.WriteLine(sprintf "List of dates first ordered by year descending, and then by month descending:"); for dt in result do Debug.WriteLine(dt.ToString("yyyy/MM/dd"))Output:
List of dates first ordered by year descending, and then by month descending: 2015-07-01 2015-03-01 2015-01-01 2014-07-01 2013-05-01