Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can you suggest any method to avoid picking of a duplicate element from an array in C#?
Posted
Updated 27-Dec-12 20:53pm
v2

Hi,

Use the Distinct extension method:
C#
int[] array = new int[7] { 7, 8, 1, 9, 10, 7, 1 };
array = array.Distinct().ToArray();

Hope this helps.
 
Share this answer
 
You can achive you aim with help of LINQ:
C#
string[] testArray=new string [3]{ "Data","Data ","One"};
var arrayWithout=testArray.Distinct().ToArray();
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900