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
Join: Joins two collections by a common key value, and is similar to inner join in SQL.
Join: Joins two collections by a common key value, and is similar to inner join in SQL. |
Join: Joins two collections by a common key value, and is similar to inner join in SQL. |
This Lambda Expression sample joins two arrays where elements match in both. |
This Lambda Expression sample joins two arrays where elements match in both. |
static void Sample_Join_Linq() { string[] warmCountries = { "Turkey", "Italy", "Spain", "Saudi Arabia", "Etiobia" }; string[] europeanCountries = { "Denmark", "Germany", "Italy", "Portugal", "Spain" }; var result = (from w in warmCountries join e in europeanCountries on w equals e select w); Debug.WriteLine("Joined countries which are both warm and European using Query Syntax:"); foreach (var country in result) Debug.WriteLine(country); }Output:
Joined countries which are both warm and European using Query Syntax: Italy Spain
Private Shared Sub Sample_Join_Linq() Dim warmCountries As String() = {"Turkey", "Italy", "Spain", "Saudi Arabia", "Etiobia"} Dim europeanCountries As String() = {"Denmark", "Germany", "Italy", "Portugal", "Spain"} Dim result = From w In warmCountries _ Join e In europeanCountries On w Equals e _ Select w Debug.WriteLine("Joined countries which are both warm and European using Query Syntax:") For Each country In result Debug.WriteLine(country) Next End SubOutput:
Joined countries which are both warm and European using Query Syntax: Italy Spain
let Sample_Join_Linq() = let warmCountries = [| "Turkey"; "Italy"; "Spain"; "Saudi Arabia"; "Etiobia" |] let europeanCountries = [| "Denmark"; "Germany"; "Italy"; "Portugal"; "Spain" |] let result = query { for w in warmCountries do join e in europeanCountries on (w = e) select w } Debug.WriteLine(sprintf "Joined countries which are both warm and European:") for country in result do Debug.WriteLine(sprintf "%s" country)Output:
Joined countries which are both warm and European: Italy Spain
static void Sample_Join_Lambda() { string[] warmCountries = { "Turkey", "Italy", "Spain", "Saudi Arabia", "Etiobia" }; string[] europeanCountries = { "Denmark", "Germany", "Italy", "Portugal", "Spain" }; var result = warmCountries.Join(europeanCountries, warm => warm, european => european, (warm, european) => warm); Debug.WriteLine("Joined countries which are both warm and Europan:"); foreach (var country in result) // Note: result is an anomymous type, thus must use a var to iterate. Debug.WriteLine(country); }Output:
Joined countries which are both warm and Europan: Italy Spain
Private Shared Sub Sample_Join_Lambda() Dim warmCountries As String() = {"Turkey", "Italy", "Spain", "Saudi Arabia", "Etiobia"} Dim europeanCountries As String() = {"Denmark", "Germany", "Italy", "Portugal", "Spain"} Dim result = warmCountries.Join(europeanCountries, Function(warm) warm, Function(european) european, Function(warm, european) warm) Debug.WriteLine("Joined countries which are both warm and Europan:") For Each country As String In result Debug.WriteLine(country) Next End SubOutput:
Joined countries which are both warm and Europan: Italy Spain
let Sample_Join_Lambda() = let warmCountries = [| "Turkey"; "Italy"; "Spain"; "Saudi Arabia"; "Etiobia" |] let europeanCountries = [| "Denmark"; "Germany"; "Italy"; "Portugal"; "Spain" |] let result = warmCountries.Join(europeanCountries, (fun warm -> warm), (fun european -> european), fun warm _ -> warm) Debug.WriteLine(sprintf "Joined countries which are both warm and European:") for country in result do Debug.WriteLine(sprintf "%s" country)Output:
Joined countries which are both warm and European: Italy Spain