Enumerable::Intersect<TSource> Method (IEnumerable<TSource>^, IEnumerable<TSource>^, IEqualityComparer<TSource>^)
Produces the set intersection of two sequences by using the specified IEqualityComparer<T> to compare values.
Assembly: System.Core (in System.Core.dll)
public: generic<typename TSource> [ExtensionAttribute] static IEnumerable<TSource>^ Intersect( IEnumerable<TSource>^ first, IEnumerable<TSource>^ second, IEqualityComparer<TSource>^ comparer )
An IEnumerable<T> whose distinct elements that also appear in second will be returned.
An IEnumerable<T> whose distinct elements that also appear in the first sequence will be returned.
Return ValueType: System.Collections.Generic::IEnumerable< >^
A sequence that contains the elements that form the set intersection of two sequences.
The type of the elements of the input sequences.
This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator method directly or by using foreach in Visual C# or For Each in Visual Basic.
The intersection of two sets A and B is defined as the set that contains all the elements of A that also appear in B, but no other elements.
When the object returned by this method is enumerated,yields distinct elements occurring in both sequences in the order in which they appear in first.
If comparer is null, the default equality comparer, Default, is used to compare values.
The following example shows how to implement an equality comparer that can be used in themethod.
After you implement this comparer, you can use sequences of Product objects in the method, as shown in the following example.
Available since 8
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1