Skip to content

Set operators

Context: Set operators (Distinct, Union, Intersect, Except, Concat) perform set operations on sequences.

int[] a = { 1, 2, 3 };
int[] b = { 3, 4, 5 };
var distinct = a.Distinct(); // 1,2,3
var union = a.Union(b); // 1,2,3,4,5
var intersect = a.Intersect(b); // 3
var except = a.Except(b); // 1,2
var concat = a.Concat(b); // 1,2,3,3,4,5

Merging user permissions: Use Union to combine permission sets from different roles.

Example: In Entity Framework Core, Union translates to SQL UNION.