Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

Enumerable.Join: practical reference

Enumerable.Join: practical reference: Performs an inner join: calls resultSelector for every equal-key pair, while an element without a match is omitted.

Version: .NET LINQ; verified on .NET 10.0.14

Syntax

source.Join(/* overload-specific arguments */)

Performs an inner join: calls resultSelector for every equal-key pair, while an element without a match is omitted.

Use it to join two sequences relationally when only matched pairs are required.

Multiple matches produce multiple results. The inner source is indexed, so its size affects memory use.

An empty source or no matches yields an empty result. Null sources, selectors, or resultSelector cause ArgumentNullException.

The complete program actually uses Enumerable.Join; its exact expected stdout is Linus:9.

Examples

using System;
using System.Collections.Generic;
using System.Linq;

var people = new[] { (Id: 1, Name: "Ada"), (Id: 2, Name: "Linus") };
var scores = new[] { (Id: 2, Score: 9) };
Console.WriteLine(string.Join(",", people.Join(scores, p => p.Id, s => s.Id, (p, s) => $"{p.Name}:{s.Score}")));

Result

Linus:9

The complete program actually uses `Enumerable.Join`; its exact expected stdout is `Linus:9`.

Sources