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
Take: Takes specified number of elements in a collection, starting from first element.
Take: Takes specified number of elements in a collection, starting from first element. |
Take: Takes specified number of elements in a collection, starting from first element. |
This Lambda Expression sample takes only 5 first numbers in array. |
This Lambda Expression sample takes only 5 first numbers in array. |
// A Query Expression cannot be constructed for Take() in C#. // Consider using a Lambda Expression instead.
Private Shared Sub Sample_Take_Linq() Dim numbers As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Dim result = From n In numbers Take 5 Debug.WriteLine("Takes the first 5 numbers only:") For Each number As Integer In result Debug.WriteLine(number) Next End SubOutput:
Takes the first 5 numbers only: 1 2 3 4 5
let Sample_Take_Linq() = let numbers = [|1; 2; 3; 4; 5; 6; 7; 8; 9; 10|]; let result = query { for n in numbers do take 5 } Debug.WriteLine("Takes the first 5 numbers only:"); for number in result do Debug.WriteLine(sprintf "%d" number)Output:
Takes the first 5 numbers only: 1 2 3 4 5
static void Sample_Take_Lambda() { int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var result = numbers.Take(5); Debug.WriteLine("Takes the first 5 numbers only:"); foreach (int number in result) Debug.WriteLine(number); }Output:
Takes the first 5 numbers only: 1 2 3 4 5
Private Shared Sub Sample_Take_Lambda() Dim numbers As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Dim result = numbers.Take(5) Debug.WriteLine("Takes the first 5 numbers only:") For Each number As Integer In result Debug.WriteLine(number) Next End SubOutput:
Takes the first 5 numbers only: 1 2 3 4 5
let Sample_Take_Lambda() = let numbers = [|1; 2; 3; 4; 5; 6; 7; 8; 9; 10|]; let result = numbers.Take(5); Debug.WriteLine("Takes the first 5 numbers only:"); for number in result do Debug.WriteLine(sprintf "%d" number)Output:
Takes the first 5 numbers only: 1 2 3 4 5