关于Hashtable删除的问题

chenli133 2006-03-06 10:54:21
我调用Hashtable.Remove(key),为什么这条记录没删除,而只是清空这条记录的值,有什么方法可以移除掉这条记录,
...全文
353 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Macosx 2006-03-06
  • 打赏
  • 举报
回复
using System;
using System.Collections;
public class SamplesHashtable {

public static void Main() {

// Creates and initializes a new Hashtable.
Hashtable myHT = new Hashtable();
myHT.Add( "1a", "The" );
myHT.Add( "1b", "quick" );
myHT.Add( "1c", "brown" );
myHT.Add( "2a", "fox" );
myHT.Add( "2b", "jumped" );
myHT.Add( "2c", "over" );
myHT.Add( "3a", "the" );
myHT.Add( "3b", "lazy" );
myHT.Add( "3c", "dog" );

// Displays the Hashtable.
Console.WriteLine( "The Hashtable initially contains the following:" );
PrintKeysAndValues( myHT );

// Removes the element with the key "3b".
myHT.Remove( "3b" );

// Displays the current state of the Hashtable.
Console.WriteLine( "After removing \"lazy\":" );
PrintKeysAndValues( myHT );
}


public static void PrintKeysAndValues( Hashtable myHT ) {
foreach ( DictionaryEntry de in myHT )
Console.WriteLine( " {0}: {1}", de.Key, de.Value );
Console.WriteLine();
}

}


/*
This code produces the following output.

The Hashtable initially contains the following:
2c: over
3a: the
2b: jumped
3b: lazy
1b: quick
3c: dog
2a: fox
1c: brown
1a: The

After removing "lazy":
2c: over
3a: the
2b: jumped
1b: quick
3c: dog
2a: fox
1c: brown
1a: The

*/
用Remove是可以正确删除的 怀疑你的代码有问题
chenli133 2006-03-06
  • 打赏
  • 举报
回复
我在监视中看了一下,count数和原来一样的,
chenli133 2006-03-06
  • 打赏
  • 举报
回复
for(int intNum=1;intNum<=HTValue.Keys.Count-intCeq;intNum++)
{
HTValue[ojbKey]=HTValue[intCeq+intNum + ",0"];
ojbKey=intCeq+intNum + ",0";
}
HTValue.Remove(ojbKey);
lovvver 2006-03-06
  • 打赏
  • 举报
回复
我测试了一下,是正常的啊:
private void Test()
{
Hashtable ht = new Hashtable() ;//<undefined>
ht.Add(1,1) ;<count=1>
ht.Add(2,2) ;<count=2>
ht.Remove(1) ;<count=1>
}
linuxyf 2006-03-06
  • 打赏
  • 举报
回复
例子:
Hashtable ht = new Hashtable();
ht.Add("0","000");

MessageBox.Show(ht.Count.ToString());
ht.Remove("0");
MessageBox.Show(ht.Count.ToString()); // 删除了
linuxyf 2006-03-06
  • 打赏
  • 举报
回复
楼主,这种情况是不太可能出现的,贴出你的代码来吧
c_delight 2006-03-06
  • 打赏
  • 举报
回复
把代码拿出来看看

应该不会的

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧