Joh*_*ohn 15
这可能不是你想要的,但如果你能控制它,最有效的方法是不首先添加它们......
你有控制权吗?如果是这样,您需要做的就是myList.Contains(currentItem)在添加项目之前进行呼叫并进行设置
您可以执行以下操作.
List<string> list = GetTheList();
Dictionary<string,object> map = new Dictionary<string,object>();
int i = 0;
while ( i < list.Count ) {
string current = list[i];
if ( map.ContainsKey(current) ) {
list.RemoveAt(i);
} else {
i++;
map.Add(current,null);
}
}
Run Code Online (Sandbox Code Playgroud)
这具有构建Dictionary<TKey,TValue>对象的开销,该对象将复制列表中的唯一值列表.但它速度相当快.
| 归档时间: |
|
| 查看次数: |
7441 次 |
| 最近记录: |