C# Array, How to make data in an array distinct from each other?

Prince OfThief picture Prince OfThief · Nov 12, 2010 · Viewed 16.3k times · Source

C# Array, How to make data in an array distinct from each other? For example

string[] a = {"a","b","a","c","b","b","c","a"}; 

how to get

string[]b = {"a","b","c"}

Answer

Aidan picture Aidan · Nov 12, 2010

Easiest way is the LINQ Distinct() command :

var b = a.Distinct().ToArray();