C# Remove Duplicates in List
2013-02-01 16:31
369 查看
有好多个方法实现
1. 用一个Dictionary实现。
参考代码
2. 用LINQ的Distinct方法。
简单的List 直接用就可以了 http://www.dotnetperls.com/remove-duplicates-list
如果是要Distinct一个类,要 Custom Comparer , 方法嘛。看这里:
http://msdn.microsoft.com/en-us/library/bb338049.aspx
1. 用一个Dictionary实现。
参考代码
static List<string> removeDuplicates(List<string> inputList) { Dictionary<string, int> uniqueStore = new Dictionary<string, int>(); List<string> finalList = new List<string>(); foreach (string currValue in inputList) { if (!uniqueStore.ContainsKey(currValue)) { uniqueStore.Add(currValue, 0); finalList.Add(currValue); } } return finalList; }
2. 用LINQ的Distinct方法。
简单的List 直接用就可以了 http://www.dotnetperls.com/remove-duplicates-list
如果是要Distinct一个类,要 Custom Comparer , 方法嘛。看这里:
http://msdn.microsoft.com/en-us/library/bb338049.aspx
相关文章推荐
- 【Leetcode】Remove Duplicates from Sorted List in JAVA
- python: remove the duplicates in a list
- 【Leetcode】Remove Duplicates from Sorted List in JAVA
- LeetCode Online Judge 题目C# 练习 - Remove Duplicates from Sorted List
- Remove duplicate in sorted linked list 1
- LeetCode Online Judge 题目C# 练习 - Remove Duplicates from Sorted List II
- Leecode Remove Duplicates from Sorted List
- [LeetCode]Remove Duplicates from Sorted List II@python
- Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- LeetCode - Remove Duplicates from Sorted List II
- leetcode 之Remove Duplicates from Sorted List
- 2.2.5 Remove Duplicates from Sorted List II
- CODE 51: Remove Duplicates from Sorted List
- [LeetCode] Remove Duplicates from Sorted List、Remove Duplicates from Sorted List II
- LeetCode(83)题解: Remove Duplicates from Sorted List
- Leetcode Remove Duplicates from Sorted List
- 【LeetCode with Python】 Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- [leet code] Remove Duplicates from Sorted List II