Export (0) Print
Expand All

Queryable.Intersect(Of TSource) Method (IQueryable(Of TSource), IEnumerable(Of TSource), IEqualityComparer(Of TSource))

Produces the set intersection of two sequences by using the specified IEqualityComparer(Of T) to compare values.

Namespace:  System.Linq
Assemblies:   System.Linq.Queryable (in System.Linq.Queryable.dll)
  System.Core (in System.Core.dll)

'Declaration
<ExtensionAttribute> _
Public Shared Function Intersect(Of TSource) ( _
	source1 As IQueryable(Of TSource), _
	source2 As IEnumerable(Of TSource), _
	comparer As IEqualityComparer(Of TSource) _
) As IQueryable(Of TSource)

Type Parameters

TSource

The type of the elements of the input sequences.

Parameters

source1
Type: System.Linq.IQueryable(Of TSource)

An IQueryable(Of T) whose distinct elements that also appear in source2 are returned.

source2
Type: System.Collections.Generic.IEnumerable(Of TSource)

An IEnumerable(Of T) whose distinct elements that also appear in the first sequence are returned.

comparer
Type: System.Collections.Generic.IEqualityComparer(Of TSource)

An IEqualityComparer(Of T) to compare values.

Return Value

Type: System.Linq.IQueryable(Of TSource)
An IQueryable(Of T) that contains the set intersection of the two sequences.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IQueryable(Of TSource). When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

ExceptionCondition
ArgumentNullException

source1 or source2 is Nothing.

The Intersect(Of TSource)(IQueryable(Of TSource), IEnumerable(Of TSource), IEqualityComparer(Of TSource)) method generates a MethodCallExpression that represents calling Intersect(Of TSource)(IQueryable(Of TSource), IEnumerable(Of TSource), IEqualityComparer(Of TSource)) itself as a constructed generic method. It then passes the MethodCallExpression to the CreateQuery(Of TElement)(Expression) method of the IQueryProvider represented by the Provider property of the source1 parameter.

The query behavior that occurs as a result of executing an expression tree that represents calling Intersect(Of TSource)(IQueryable(Of TSource), IEnumerable(Of TSource), IEqualityComparer(Of TSource)) depends on the implementation of the type of the source1 parameter. The expected behavior is that all the elements in source1 that are also in source2 are returned. The comparer parameter is used to compare elements.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft