Skip to content

Instantly share code, notes, and snippets.

@ccellar
Last active September 26, 2015 18:48
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ccellar/1143060 to your computer and use it in GitHub Desktop.
Remove duplicate in a list
private static List<T> RemoveDoubleItems<T>(List<T> list)
{
var newList = new List<T>();
var keyList = new Dictionary<T,string>();
foreach (T item in list)
{
if (!keyList.ContainsKey(item))
{
keyList.Add(item, string.Empty);
newList.Add(item);
}
}
return newList;
}
private static List<T> RemoveDoubleItems<T>(List<T> list)
{
return list.Distinct().ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment