Get Distinct value from a string array in CSharp

Description

The following code shows how to get Distinct value from a string array.

Example


     /*  w  ww. j a  v a  2s  .c o  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 ShowDistinct = First.Distinct();

         // Display the output.
         Console.WriteLine("Distinct:");
         foreach (String ThisElement in ShowDistinct)
            Console.WriteLine(ThisElement);

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ