VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/linq-set-operator-intersect/

⇱ LINQ | Set Operator | Intersect - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LINQ | Set Operator | Intersect

Last Updated : 22 May, 2019
In LINQ, Set operators are those operators in query expression which return a result set which is based on the existence or non-existence of the equivalent elements within the same or different collections or sequences or sets. The standard query operator contains the following set operators:
  1. Union
  2. Intersect
  3. Except
  4. Distinct

Intersect Operator

The Intersect operator returns the set intersection. Or in other words, we can say that it return the set or collection which contain the common elements appears in two collections, or sets. 👁 Image
  • It does not support query syntax in C# and VB.Net languages. But you can use Intersect method on query variable or you can wrap your query in brackets and then the call Intersect method.
  • It support method syntax in both C# and VB.Net languages.
  • It present in both the Queryable and Enumerable class.
  • It is implemented by using deferred execution.
  • When you are working with the collections of complex types, then you must use IEqualityComparer interface, otherwise the Intersect method will give you incorrect result.
Example 1:
Output:
Sequence 1 is: 
m
q
o
s
y
a
Sequence 2 is: 
p
t
r
s
y
z
New Sequence: 
s
y
Example 2:
Output:
Commonly known Languages: 
C#
Java
Comment
Article Tags:
Article Tags:

Explore