110,534
社区成员
发帖
与我相关
我的任务
分享
//定义的集合
private Hashtable taskList = Hashtable.Synchronized(new Hashtable());
//遍历集合(集合是有数据的,我填充了)
if (taskList != null && taskList.Count > 0)
{
foreach (Object key in taskList.Keys)
{
//这里省略业务
}
}
//移除集合元素的方法
private void RemoveTask(int key)
{
if (taskList.Contains(key))
taskList.Remove(key);
}
//是否锁住集合
private bool look = false;
//删除集合操作
private void RemoveTask(int key)
{
look = true;
for (int i = taskList.Count - 1; i > -1; i--)
{
if (key == Convert.ToInt32(taskList[i]))
{
taskList.Remove(taskList[i]);
look = false;
break;
}
}
}
//遍历集合
if (taskList != null && taskList.Count > 0 && !look)
{
for (int i = 0; i < taskList.Count; i++)
{
//省略业务逻辑
}
}
Hashtable ht=new Hashtable();
ht.Add("1","1");
string[] t = new[] {"1", "2", "3"};
foreach (var s in t)
{
if (ht.ContainsKey(s))
ht.Remove(s);
}
// Returns an enumerator for this list with the given
// permission for removal of elements. If modifications made to the list
// while an enumeration is in progress, the MoveNext and
// GetObject methods of the enumerator will throw an exception.
//
public Enumerator GetEnumerator() {
return new Enumerator(this);
}