Home
Manage Your Code
Snippet: RemoveDuplicates (C#)
Title: RemoveDuplicates Language: C#
Description: Removes duplicate values from a list. Views: 735
Author: Mihir Shah Date Added: 9/16/2008
Copy Code  
1private static List<int> RemoveDuplicates(IEnumerable<int> inputList)
2{
3     Dictionary<int, int> uniqueStore = new Dictionary<int, int>();
4     List<int> finalList = new List<int>();
5
6     foreach (int currValue in inputList)
7     {
8          if (!uniqueStore.ContainsKey(currValue))
9          {
10               uniqueStore.Add(currValue, 0);
11               finalList.Add(currValue);
12          }
13     }
14     return finalList;
15}
Usage
IList uniqueList = RemoveDuplicates(itemOrderIdList);