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
ElementAtOrDefault: Retrieves element from a collection at specified (zero-based) index, but gets default value if out-of-range.
ElementAtOrDefault: Retrieves element from a collection at specified (zero-based) index, but gets default value if out-of-range. |
ElementAtOrDefault: Retrieves element from a collection at specified (zero-based) index, but gets default value if out-of-range. |
This Query Expression sample retrieves elements at index 1 and 10 from array, and because index 10 is out-of-range, it gets default value (null). |
This Query Expression sample retrieves elements at index 1 and 10 from array, and because index 10 is out-of-range, it gets default value (null). |
// A Query Expression cannot be constructed for ElementAtOrDefault() in C#. // Consider using a Lambda Expression instead.
' A Query Expression cannot be constructed for ElementAtOrDefault() in VB.NET. ' Consider using a Lambda Expression instead.
// A Query Expression cannot be constructed for ElementAtOrDefault() in F#. // Consider using a Lambda Expression instead.
static void Sample_ElementAtOrDefault_Lambda() { string[] colors = { "Red", "Green", "Blue" }; var resultIndex1 = colors.ElementAtOrDefault(1); var resultIndex10 = colors.ElementAtOrDefault(10); Debug.WriteLine("Element at index 1 in the array contains:"); Debug.WriteLine(resultIndex1); Debug.WriteLine("Element at index 10 in the array does not exist:"); Debug.WriteLine(resultIndex10 == null); }Output:
Element at index 1 in the array contains: Green Element at index 10 in the array does not exist: True
Private Shared Sub Sample_ElementAtOrDefault_Lambda() Dim colors As String() = {"Red", "Green", "Blue"} Dim resultIndex1 = colors.ElementAtOrDefault(1) Dim resultIndex10 = colors.ElementAtOrDefault(10) Debug.WriteLine("Element at index 1 in the array contains:") Debug.WriteLine(resultIndex1) Debug.WriteLine("Element at index 10 in the array does not exist:") Debug.WriteLine(resultIndex10 Is Nothing) End SubOutput:
Element at index 1 in the array contains: Green Element at index 10 in the array does not exist: True
let Sample_ElementAtOrDefault_Lambda() = let colors = [|"Red"; "Green"; "Blue"|] let resultIndex1 = colors.ElementAtOrDefault(1) let resultIndex10 = colors.ElementAtOrDefault(10) Debug.WriteLine("Element at index 1 in the array contains:"); Debug.WriteLine(sprintf "%s" resultIndex1); Debug.WriteLine("Element at index 10 in the array does not exist:") Debug.WriteLine(sprintf "%b" (resultIndex10 = null))Output:
Element at index 1 in the array contains: Green Element at index 10 in the array does not exist: true