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
Intersect: Takes only the elements that are shared between two collections.
Intersect: Takes only the elements that are shared between two collections. |
Intersect: Takes only the elements that are shared between two collections. |
This Lambda Expression sample creates a new collection with values shared between the two arrays. |
This Lambda Expression sample creates a new collection with values shared between the two arrays. |
static void Sample_Intersect_Linq() { int[] numbers1 = { 1, 2, 3 }; int[] numbers2 = { 3, 4, 5 }; var result = (from n in numbers1.Intersect(numbers2) select n); Debug.WriteLine("Intersect creates a single sequence with only the duplicates:"); foreach (int number in result) Debug.WriteLine(number); }Output:
Intersect creates a single sequence with only the duplicates: 3
Private Shared Sub Sample_Intersect_Linq() Dim numbers1 As Integer() = {1, 2, 3} Dim numbers2 As Integer() = {3, 4, 5} Dim result = From n In numbers1.Intersect(numbers2) Select n Debug.WriteLine("Intersect creates a single sequence with only the duplicates:") For Each number As Integer In result Debug.WriteLine(number) Next End SubOutput:
Intersect creates a single sequence with only the duplicates: 3
let Sample_Intersect_Linq() = let numbers1 = [| 1; 2; 3 |] let numbers2 = [| 3; 4; 5 |] let result = query { for n in numbers1.Intersect(numbers2) do select n } Debug.WriteLine(sprintf "Intersect creates a single sequence with only the duplicates:") for number in result do Debug.WriteLine(sprintf "%d" number)Output:
Intersect creates a single sequence with only the duplicates: 3
static void Sample_Intersect_Lambda() { int[] numbers1 = { 1, 2, 3 }; int[] numbers2 = { 3, 4, 5 }; var result = numbers1.Intersect(numbers2); Debug.WriteLine("Intersect creates a single sequence with only the duplicates:"); foreach (int number in result) Debug.WriteLine(number); }Output:
Intersect creates a single sequence with only the duplicates: 3
Private Shared Sub Sample_Intersect_Lambda() Dim numbers1 As Integer() = {1, 2, 3} Dim numbers2 As Integer() = {3, 4, 5} Dim result = numbers1.Intersect(numbers2) Debug.WriteLine("Intersect creates a single sequence with only the duplicates:") For Each number As Integer In result Debug.WriteLine(number) Next End SubOutput:
Intersect creates a single sequence with only the duplicates: 3
let Sample_Intersect_Lambda() = let numbers1 = [| 1; 2; 3 |] let numbers2 = [| 3; 4; 5 |] let result = numbers1.Intersect(numbers2) Debug.WriteLine(sprintf "Intersect creates a single sequence with only the duplicates:") for number in result do Debug.WriteLine(sprintf "%d" number)Output:
Intersect creates a single sequence with only the duplicates: 3