Code Snippet: Remove Duplicates From ArrayList

30. April 2011 02:51

C# Code Snippets  0 Comments

Two methods to remove Duplicates from ArrayList.

Method 1:

private static ArrayList RemoveDuplicates(ArrayList arrList) 
        ArrayList list = new ArrayList();
        foreach (string item in arrList) 
             if (!list.Contains(item)) 
        return list; 

Method 2:

private static string[] RemoveDuplicates(ArrayList arrList)
        HashSet<string> Hset = new HashSet<string>((string[])arrList.ToArray(typeof(string)));
        string[] Result = new string[Hset.Count];
        return Result;

Disclaimer: I found this method on the net and therefore I am sharing it as it is. Use any of the above which suites your requirement.

 No Rating

Comments (0)

Add Comment

Visit to discover Indian blogs Computers Blogs