Intersect two string arrays in CSharp

Description

The following code shows how to intersect two string arrays.

Example


     /*  www  .jav a 2 s.co m*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;


public class MainClass{

   public static void Main(string[] args){   
         String[] First = { "One", "Two", "Two", "Three", "Four" };
         String[] Second = { "Three", "Four", "Five", "Six" };

         var ShowIntersect = First.Intersect(Second);

         Console.WriteLine("Intersect:");
         foreach (String ThisElement in ShowIntersect)
            Console.WriteLine(ThisElement);

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ