Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

i have one arraylist wich contain values from different database but it stores some duplicate values so, i want to remove duplicate values and store only unique value in ARRay List.

So, how can this is achievable ?


Thanks in Advance...
Mitesh
Posted

You can use a temporary container such as HashSet and adding all element to it. Finally copy the data of HashSet to ArrayList.

Cheers..
 
Share this answer
 
ArrayList ar = new ArrayList();

for (int h = 0; h<ds1.Tables[0].Rows.Count; h++)
{
    if (!ar.Contains(ds1.Tables[0].Rows[h][0].ToString()))
    {
        ar.Add(Convert.ToString(ds1.Tables[0].Rows[h][0].ToString()));
    }
}
 
Share this answer
 

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