CKTIS / C#
Enumerable.Union: practical reference
Enumerable.Union: practical reference: The deferred result yields unique elements of the first source and then new unique elements of the second under the comparer.
Version: .NET LINQ; verified on .NET 10.0.14
Syntax
source.Union(/* overload-specific arguments */)The deferred result yields unique elements of the first source and then new unique elements of the second under the comparer.
Use it for set union when duplicates must be removed.
It needs a set of seen elements and does not preserve duplicate counts. Order is not a sorting contract.
Two empty sources yield an empty result; a null source causes ArgumentNullException.
The complete program actually uses Enumerable.Union; its exact expected stdout is 1,2,3.
Examples
using System;
using System.Collections.Generic;
using System.Linq;
Console.WriteLine(string.Join(",", new[] { 1, 2 }.Union(new[] { 2, 3 })));
Result
1,2,3
The complete program actually uses `Enumerable.Union`; its exact expected stdout is `1,2,3`.