Set Operations (C#)
Set operations in LINQ refer to query operations that produce a result set that is based on the presence or absence of equivalent elements within the same or separate collections (or sets).
The standard query operator methods that perform set operations are listed in the following section.
|Method Name||Description||C# Query Expression Syntax||More Information|
|Distinct||Removes duplicate values from a collection.||Not applicable.||Enumerable.Distinct
|Except||Returns the set difference, which means the elements of one collection that do not appear in a second collection.||Not applicable.||Enumerable.Except
|Intersect||Returns the set intersection, which means elements that appear in each of two collections.||Not applicable.||Enumerable.Intersect
|Union||Returns the set union, which means unique elements that appear in either of two collections.||Not applicable.||Enumerable.Union
Comparison of Set Operations
The following illustration depicts the behavior of the Enumerable.Distinct method on a sequence of characters. The returned sequence contains the unique elements from the input sequence.
The following illustration depicts the behavior of Enumerable.Except. The returned sequence contains only the elements from the first input sequence that are not in the second input sequence.
The following illustration depicts the behavior of Enumerable.Intersect. The returned sequence contains the elements that are common to both of the input sequences.
The following illustration depicts a union operation on two sequences of characters. The returned sequence contains the unique elements from both input sequences.
Send feedback about: