有好多个方法实现
1. 用一个Dictionary实现。
参考代码
static ListremoveDuplicates(List inputList){Dictionary uniqueStore = new Dictionary ();List finalList = new List (); 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