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
Max: Finds the largest value in a collection.
Max: Finds the largest value in a collection. |
Max: Finds the largest value in a collection. |
This Lambda Expression sample finds the highest number in array. |
This Lambda Expression sample finds the highest number in array. |
// A Query Expression cannot be constructed for Max() in C#. // Consider using a Lambda Expression instead.
Private Shared Sub Sample_Max_Linq() Dim numbers As Integer() = {2, 8, 5, 6, 1} Dim result = Aggregate n In numbers Into Max() Debug.WriteLine("Highest number is:") Debug.WriteLine(result) End SubOutput:
Highest number is: 8
// There is no Max() for Query Expressions in F#, but it has the similar "maxBy". let Sample_Max_Linq = let numbers = [|2; 8; 5; 6; 1|] let result = query { for n in numbers do maxBy n } Debug.WriteLine(sprintf "Highest number is:") Debug.WriteLine(sprintf "%d" result)Output:
Highest number is: 8
static void Sample_Max_Lambda() { int[] numbers = { 2, 8, 5, 6, 1 }; var result = numbers.Max(); Debug.WriteLine("Highest number is:"); Debug.WriteLine(result); }Output:
Highest number is: 8
Private Shared Sub Sample_Max_Lambda() Dim numbers As Integer() = {2, 8, 5, 6, 1} Dim result = numbers.Max() Debug.WriteLine("Highest number is:") Debug.WriteLine(result) End SubOutput:
Highest number is: 8
let Sample_Max_Lambda() = let numbers = [|2; 8; 5; 6; 1|] let result = numbers.Max() Debug.WriteLine(sprintf "Highest number is:") Debug.WriteLine(sprintf "%d" result)Output:
Highest number is: 8