Mega Code Archive

 
Categories / C# / LINQ
 

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