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
Where: Filters elements from a collection to satisfy a specified condition. Use overloaded Index to pass index.
Where: Filters elements from a collection to satisfy a specified condition. Use overloaded Index to pass index. |
Where: Filters elements from a collection to satisfy a specified condition. Use overloaded Index to pass index. |
This Lambda Expression sample finds numbers divisible by 3 and element index >= 5. |
This Lambda Expression sample finds numbers divisible by 3 and element index >= 5. |
static void Sample_Where_Linq_Indexed() { int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var result = from n in numbers.Select((Value, Index) => new {Value, Index}) where (n.Value % 3 == 0 && n.Index >= 5) select n.Value; Debug.WriteLine("Numbers divisible by 3 and indexed >= 5:"); foreach (var number in result) Debug.WriteLine(number); }Output:
Numbers divisible by 3 and indexed >= 5: 6 9
Private Shared Sub Sample_Where_Linq_Indexed() Dim numbers As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Dim result = From n In numbers.Select(Function(Value, Index) New With {Value, Index}) _ Where (n.Value Mod 3 = 0 AndAlso n.Index >= 5) Select n.Value Debug.WriteLine("Numbers divisible by 3 and indexed >= 5:") For Each number In result Debug.WriteLine(number) Next End SubOutput:
Numbers divisible by 3 and indexed >= 5: 6 9
static void Sample_Where_Lambda_Indexed() { int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var result = numbers.Where((n, i) => n % 3 == 0 && i >= 5); Debug.WriteLine("Numbers divisible by 3 and indexed >= 5:"); foreach (var number in result) Debug.WriteLine(number); }Output:
Numbers divisible by 3 and indexed >= 5: 6 9
Private Shared Sub Sample_Where_Lambda_Indexed() Dim numbers As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Dim result = numbers.Where(Function(n, i) n Mod 3 = 0 AndAlso i >= 5) Debug.WriteLine("Numbers divisible by 3 and indexed >= 5:") For Each number In result Debug.WriteLine(number) Next End SubOutput:
Numbers divisible by 3 and indexed >= 5: 6 9
let Sample_Where_Lambda_Indexed() = let numbers = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10] let result = numbers.Where(fun n i -> n % 3 = 0 && i >= 5) Debug.WriteLine(sprintf "Numbers divisible by 3 and indexed >= 5:") for number in result do Debug.WriteLine(sprintf "%d" number)Output:
Numbers divisible by 3 and indexed >= 5: 6 9