Remove duplicate in a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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