Intersect results from Take and Skip in CSharp

Description

The following code shows how to intersect results from Take and Skip.

Example


   /*from   www.jav a 2  s  .  c o m*/

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

public class MainClass {
    public static void Main() {
        string[] presidents = {"HTML", "HTML5", "CSS", "CSS3", "Java", "XML"};
        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);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ