Fork me on GitHub

11/26/2009

[C#] 移除 List 當中重複的物件

Private 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;
}

No comments:

Post a Comment