//created based on http://www.kirupa.com/net/removingDuplicates2.htm
//Why it is not in .Net Framework yet? Why HashSet<T> is only in Orcas(http://blogs.msdn.com/bclteam/archive/2006/11/09/introducing-hashset-t-kim-hamilton.aspx)
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);
finalList.Add(currValue);
}
}
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 @ Tuesday, September 11, 2007 3:42 PM