HashTable疯了...... [英] HashTable gone nuts...

查看:66
本文介绍了HashTable疯了......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在使用散列表来存储我的数组中的一堆数字:


Hashtable应该看起来像:

键值

1 01234

2 01235

3 01245

....

10 23456

我使用一个模块来保持我的Hashtable活着。所有时间/整个期间

运行时间:


模块ModGlobVariablen

Public lfdNrHash As Integer = 1

Public myHashTable As New Hashtable

结束模块


我有一个子程序(非常简单)我每次调用时都会调用

数组已更改:


Private Sub FillHashTable(ByVal Wert)


myHashTable.Add(lfdNrHash,Wert)

lfdNrHash = lfdNrHash + 1

End Sub


一切正常,没有错误引发,但如果我调试step-by.step我

看到以下结果:


键值

1 23456

2 23456

3 23456

...

10 23456


因为这是正确的每个HashTable Key中的数据,但最后所有

数据都被我的数组的最后一个值覆盖!

含义每个myHashTable.Add(lfdNrHash,Wert) "删除所有旧的

哈希表值(不是键)并用新数组替换它们

值!


为什么会这样做? ; myHashTable.add"那样做吗?

每次写入一个带有新密钥的新值时,旧前缀值

都会被覆盖.....


请帮助。


-

通过.NET新闻组发送
http://www.dotnetnewsgroups.com

解决方案

" Q" < MI ** @ gmx.net> schrieb



我正在使用散列表来存储我的
数组中的一堆数字:

Hashtable应该是这样的:

键值
1 01234
2 01235
3 01245
...
10 23456
我使用一个模块来保持我的Hashtable活着。所有时间/在整个运行时期间:

模块ModGlobVariablen
公共lfdNrHash作为整数= 1
公共myHashTable作为新的Hashtable
结束模块
我有一个子程序(非常简单),每当我的数组中的值发生变化时我都会调用它:

Private Sub FillHashTable(ByVal Wert)

myHashTable.Add(lfdNrHash,Wert)
lfdNrHash = lfdNrHash + 1



一切正常,没有错误,但如果我调试了
step-by.step我看到以下结果:

键值
1 23456
2 23456
3 23456
。 。
10 23456

因为每个HashTable Key中都有正确的数据,但最后
所有数据都被我的数组的最后一个值覆盖!
含义每个myHashTable.Add(lfdNrHash,Wert)删除所有旧的散列值(不是键)并用新的
数组值替换它们!

为什么myHashTable.add这样做?
每次写入一个带有新密钥的新值时,旧的前缀
值都会被覆盖.....

请帮助。



添加到Hashtable的对象的类型是什么?您删除了子FillHashTable参数的数据

类型。我猜它不是整数,是吗?

如果它是一个参考类型,也许你不会创建新的实例但是改变了b $ b的价值你多次添加的单个实例的属性。

只是一个猜测。

Armin


< blockquote>


除了Armin的评论。我尝试了这个,它的工作原理是

预期。

FillHashTable(测试)

FillHashTable(Color.Red)

FillHashTable(Brushes.Green)

FillHashTable(Me.Controls)


For each de As DictionaryEntry in myHashTable

Trace.WriteLine(String.Format(" {0} {1}",de.Key,de.Value))

下一页

并获得关注输出


4 System.Windows.Forms.Form + ControlCollection

3 System.Drawing.SolidBrush

2颜色[红色]

1测试



----------------------- ---

" Q" < MI ** @ gmx.net>在消息中写道

news:ur ************** @ tk2msftngp13.phx.gbl ...


我正在使用散列表来存储我的数组中的一堆数字:

Hashtable应该如下所示:

键值 1 01234
2 01235
3 01245
10 23456
我使用一个模块来保持我的Hashtable活着。所有时间/整个
运行时间:

模块ModGlobVariablen
公共lfdNrHash作为整数= 1
公共myHashTable作为新的Hashtable
结束模块
我有一个子程序(非常简单),每当我的
数组中的值发生变化时我都会调用它:

Private Sub FillHashTable(ByVal Wert)

myHashTable.Add(lfdNrHash,Wert)
lfdNrHash = lfdNrHash + 1



一切正常,没有错误,但如果我调试step-by.step我看到以下结果:

键值
1 23456
2 23456
3 23456
。 。
10 23456

因为每个HashTable Key中都有正确的数据,但最后所有的数据都会被我的数组的最后一个值覆盖!
含义每个myHashTable.Add(lfdNrHash,Wert)删除所有旧的哈希表值(而不是键),并用新数组值取代它们!

为什么myHashTable.add?这样做?
每次写入一个带有新密钥的新值时,旧的前体值
都会被覆盖.....

请帮忙。

-
通过.NET新闻组发送
http:// www。 dotnetnewsgroups.com



您好

您是否通过新关键字重新创建对象似乎相同? br />
再次。看起来就像你一次又一次地添加同一个对象。

Shivprasad Koirala

C#,VB.NET,SQL服务器,ASP.NET访谈问题
http://www.geocities.com/ dotnetinterviews /


Hi,

I''m using a hashtable to store away a bunch of numbers from my array:

The Hashtable should look like:
Key Value
1 01234
2 01235
3 01245
....
10 23456
I use a module to keep my Hashtable "alive" all times/during the whole
runtime:

Module ModGlobVariablen
Public lfdNrHash As Integer = 1
Public myHashTable As New Hashtable
End Module

I do have a subroutine (very simple)that I call each time a value in my
array has changed:

Private Sub FillHashTable(ByVal Wert)

myHashTable.Add(lfdNrHash, Wert)
lfdNrHash = lfdNrHash + 1

End Sub

Everything works fine, no error is raised, but if I debug step-by.step I
see the following result:

Key Value
1 23456
2 23456
3 23456
...
10 23456

Befor there was correct data in each HashTable Key, but in the end all
data is overwritten with the last value of my array !
Meaning each "myHashTable.Add(lfdNrHash, Wert)" deletes all old
hashtable values (not the keys) and replaces them with the new array
value!

Why does "myHashTable.add" do that?
Each time a new value with a new key is written, the old precursor value
is overwritten.....

Pls help.

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com

解决方案

"Q" <MI**@gmx.net> schrieb

Hi,

I''m using a hashtable to store away a bunch of numbers from my
array:

The Hashtable should look like:
Key Value
1 01234
2 01235
3 01245
...
10 23456
I use a module to keep my Hashtable "alive" all times/during the
whole runtime:

Module ModGlobVariablen
Public lfdNrHash As Integer = 1
Public myHashTable As New Hashtable
End Module

I do have a subroutine (very simple)that I call each time a value in
my array has changed:

Private Sub FillHashTable(ByVal Wert)

myHashTable.Add(lfdNrHash, Wert)
lfdNrHash = lfdNrHash + 1

End Sub

Everything works fine, no error is raised, but if I debug
step-by.step I see the following result:

Key Value
1 23456
2 23456
3 23456
..
10 23456

Befor there was correct data in each HashTable Key, but in the end
all data is overwritten with the last value of my array !
Meaning each "myHashTable.Add(lfdNrHash, Wert)" deletes all old
hashtable values (not the keys) and replaces them with the new
array value!

Why does "myHashTable.add" do that?
Each time a new value with a new key is written, the old precursor
value is overwritten.....

Pls help.


What is the type of the objects added to the Hashtable? You dropped the data
type of the parameter of sub FillHashTable. I guess it''s not Integer, is it?
If it''s a reference type, maybe you don''t create new instances but change
the value of a property of one single instance that you add multiple times.
Just a guess.
Armin


Hi,

In addition to Armin''s comments. I tried this and it worked as
expected.
FillHashTable("Test")
FillHashTable(Color.Red)
FillHashTable(Brushes.Green)
FillHashTable(Me.Controls)

For Each de As DictionaryEntry In myHashTable
Trace.WriteLine(String.Format("{0} {1}", de.Key, de.Value))
Next
And get the follow output

4 System.Windows.Forms.Form+ControlCollection
3 System.Drawing.SolidBrush
2 Color [Red]
1 Test
Ken
--------------------------
"Q" <MI**@gmx.net> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...

Hi,

I''m using a hashtable to store away a bunch of numbers from my array:

The Hashtable should look like:
Key Value
1 01234
2 01235
3 01245
...
10 23456
I use a module to keep my Hashtable "alive" all times/during the whole
runtime:

Module ModGlobVariablen
Public lfdNrHash As Integer = 1
Public myHashTable As New Hashtable
End Module

I do have a subroutine (very simple)that I call each time a value in my
array has changed:

Private Sub FillHashTable(ByVal Wert)

myHashTable.Add(lfdNrHash, Wert)
lfdNrHash = lfdNrHash + 1

End Sub

Everything works fine, no error is raised, but if I debug step-by.step I
see the following result:

Key Value
1 23456
2 23456
3 23456
..
10 23456

Befor there was correct data in each HashTable Key, but in the end all
data is overwritten with the last value of my array !
Meaning each "myHashTable.Add(lfdNrHash, Wert)" deletes all old
hashtable values (not the keys) and replaces them with the new array
value!

Why does "myHashTable.add" do that?
Each time a new value with a new key is written, the old precursor value
is overwritten.....

Pls help.

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com



Hi
You wert object seems to be same do you recreate it by new keyword
again.Looks like you are adding the same object again and again.

Shivprasad Koirala
C# , VB.NET , SQL SERVER , ASP.NET Interview Questions
http://www.geocities.com/dotnetinterviews/


这篇关于HashTable疯了......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆