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
First: Retrieves first element from a collection. Throws exception if collection is empty.
First: Retrieves first element from a collection. Throws exception if collection is empty. |
First: Retrieves first element from a collection. Throws exception if collection is empty. |
This Lambda Expression sample takes first element from collection which is 6 characters long. |
This Lambda Expression sample takes first element from collection which is 6 characters long. |
// A Query Expression cannot be constructed for First() in C#. // Consider using a Lambda Expression instead.
' A Query Expression cannot be constructed for First() in VB.NET. ' Consider using a Lambda Expression instead.
let Sample_First_Linq_Conditional() = let countries = [|"Denmark"; "Sweden"; "Norway"|] let result = query { for f in countries do where (f.Length = 6) head } Debug.WriteLine(sprintf "First element with a length of 6 characters:") Debug.WriteLine(sprintf "%s" result)Output:
First element with a length of 6 characters: Sweden
static void Sample_First_Lambda_Conditional() { string[] countries = { "Denmark", "Sweden", "Norway" }; var result = countries.First(c => c.Length == 6); Debug.WriteLine("First element with a length of 6 characters:"); Debug.WriteLine(result); }Output:
First element with a length of 6 characters: Sweden
Private Shared Sub Sample_First_Lambda_Conditional() Dim countries As String() = {"Denmark", "Sweden", "Norway"} Dim result = countries.First(Function(c) c.Length = 6) Debug.WriteLine("First element with a length of 6 characters:") Debug.WriteLine(result) End SubOutput:
First element with a length of 6 characters: Sweden
let Sample_First_Lambda_Conditional() = let countries = [|"Denmark"; "Sweden"; "Norway"|] let result = countries.First(fun c -> c.Length = 6) Debug.WriteLine(sprintf "First element with a length of 6 characters:") Debug.WriteLine(sprintf "%s" result)Output:
First element with a length of 6 characters: Sweden