Geeks With Blogs

Michael Freidgeim's Blog MS .Net Development

        //created based on

        //Why it is not in .Net Framework yet? Why HashSet<T> is only in Orcas(

        public static List<GenericType> removeDuplicates<GenericType>(List<GenericType> inputList)


            Dictionary<GenericType, int> uniqueStore = new Dictionary<GenericType, int>();

            List<GenericType> finalList = new List<GenericType>();


            foreach (GenericType currValue in inputList)


                if (!uniqueStore.ContainsKey(currValue))


                    uniqueStore.Add(currValue, 0);




            return finalList;



Alternative solution is to use List.RemoveAll(Predicate<T>) -(misleading name for the function, that allow to remove only specified by Predicate)


Posted on Tuesday, September 11, 2007 3:42 PM .Net Framework | Back to top

Comments on this post: Generic function to removeDuplicates from Generic List

# re: Generic function to removeDuplicates from Generic List
Requesting Gravatar...
In 3.5 the function is obsolete, use LINQ Distinct() instead
Left by Michael Freidgeim on Jul 26, 2009 2:17 AM

Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: | Join free