Intersect Operator : Intersect « LINQ « C# / C Sharp






Intersect Operator

 

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);
    }
}

 








Related examples in the same category

1.use Linq Intersect to intersect two arrays
2.prints a list of numbers that are common to two integer arrays.
3.prints the first letter of a Product name and the first letter of a Customer name.