社区
C#
帖子详情
关于Hashtable删除的问题
chenli133
2006-03-06 10:54:21
我调用Hashtable.Remove(key),为什么这条记录没删除,而只是清空这条记录的值,有什么方法可以移除掉这条记录,
...全文
367
7
打赏
收藏
关于Hashtable删除的问题
我调用Hashtable.Remove(key),为什么这条记录没删除,而只是清空这条记录的值,有什么方法可以移除掉这条记录,
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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
打赏
举报
回复
把代码拿出来看看
应该不会的
WinForm
HashTable
最简单用法,.net
hashtable
,
hashtable
,
hashtable
用法
WinForm
HashTable
最简单用法,.net
hashtable
,
hashtable
,
hashtable
用法
C#中关于序列化
HashTable
的具体用法详解
C#中关于序列化
HashTable
的具体用法详解
asp.net遍历
hashtable
利用asp.net遍历
hashtable
中的值
hashtable
存储数据.rar
Hashtable
存储数据例子,希望大家多多指教
C#-
Hashtable
应用
该文档实现了
Hashtable
在C#中的常用的函数
C#
111,120
社区成员
642,545
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章