CKTIS / C#
Enumerable.Intersect: practical reference
Enumerable.Intersect: practical reference: The deferred result returns unique elements of the first source also present in the second under the comparer.
Version: .NET LINQ; verified on .NET 10.0.14
Syntax
source.Intersect(/* overload-specific arguments */)The deferred result returns unique elements of the first source also present in the second under the comparer.
Use it for set intersection when repetitions do not matter.
The second source is buffered; this is not multiset intersection and duplicate counts are not preserved.
If either source is empty, the result is empty. Null sources cause ArgumentNullException.
The complete program actually uses Enumerable.Intersect; its exact expected stdout is 2,3.
Examples
using System;
using System.Collections.Generic;
using System.Linq;
Console.WriteLine(string.Join(",", new[] { 1, 2, 2, 3 }.Intersect(new[] { 2, 3, 4 })));
Result
2,3
The complete program actually uses `Enumerable.Intersect`; its exact expected stdout is `2,3`.