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,3var union = a.Union(b); // 1,2,3,4,5var intersect = a.Intersect(b); // 3var except = a.Except(b); // 1,2var concat = a.Concat(b); // 1,2,3,3,4,5Real-world usage example
Section titled “Real-world usage example”Merging user permissions: Use Union to combine permission sets from different roles.
Example: In Entity Framework Core, Union translates to SQL UNION.