Intersect Operator : Intersect « LINQ « C# / CSharp Tutorial






using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass {
    public static void Main() {
        string[] presidents = {"G", "H", "a", "H", "over", "Jack"};
        IEnumerable<string> first = presidents.Take(5);
        IEnumerable<string> second = presidents.Skip(4);
        IEnumerable<string> intersect = first.Intersect(second);

        Console.WriteLine("The count of the array is: " + presidents.Count());
        Console.WriteLine("The count of the first sequence is: " + first.Count());
        Console.WriteLine("The count of the second sequence is: " + second.Count());
        Console.WriteLine("The count of the intersect sequence is: " + intersect.Count());
        foreach (string name in intersect)
            Console.WriteLine(name);
    }
}








22.50.Intersect
22.50.1.Using Linq Intersect to intersect two arrays
22.50.2.prints a list of numbers that are common to two integer arrays.
22.50.3.prints the first letter of a Product name and the first letter of a Customer name.
22.50.4.Intersect Operator
22.50.5.Set Operators: Intersect
22.50.6.Create the Intersect query