473,383 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

HashTables and scoping

Hey All,

I cant VERIFY this, but it makes sense so I thought I'd trow up my theory
and see if it made sense to any of you... and then ask how to get around it.
hehe

I've got a Class1[] that I'm wanting to load into a hash table, so, I
basically (at this point) run through a loop and do a
Hashtable.Add(Class1[index].key,Class1[index])

However, later when I try to get out the value out of the HashTable... The
value is null.

I'm thinking this is because the array that initially had the values has
gone out of scope .. and the hashtable only stored a reference to the
object.. so now, the refence is null. If this is true, how do I get
around that? If it is not true, does anyone know why I'm not getting my
values out?

- Roger
Nov 16 '05 #1
2 1113
Roger,

This is not the case. When you assign Class1[index] to the hashtable,
the hashtable holds a reference to the object in the array. If the array
goes out of scope, as long as the hashtable is in scope, then the references
are still valid.

It is something else that is causing the values in the hashtable to be
null.

The only things I can think of are that the value at Class1[index] is
already null, and it's null when it goes in, or there is an explicit setting
of the value for that key to null.

Can you provide a sample project which shows the error?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roger Webb" <rw***@nos.twia.org> wrote in message
news:Oq**************@TK2MSFTNGP10.phx.gbl...
Hey All,

I cant VERIFY this, but it makes sense so I thought I'd trow up my theory
and see if it made sense to any of you... and then ask how to get around
it.
hehe

I've got a Class1[] that I'm wanting to load into a hash table, so, I
basically (at this point) run through a loop and do a
Hashtable.Add(Class1[index].key,Class1[index])

However, later when I try to get out the value out of the HashTable... The
value is null.

I'm thinking this is because the array that initially had the values has
gone out of scope .. and the hashtable only stored a reference to the
object.. so now, the refence is null. If this is true, how do I get
around that? If it is not true, does anyone know why I'm not getting my
values out?

- Roger

Nov 16 '05 #2
I know that the values going in are non-null, mainly becasue the key value
is a property of the class being added. So I will investigate that it is
beign set null somewhere that I am unaware of.

Thanks for the reply.

- Roger
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O9**************@TK2MSFTNGP15.phx.gbl...
Roger,

This is not the case. When you assign Class1[index] to the hashtable,
the hashtable holds a reference to the object in the array. If the array
goes out of scope, as long as the hashtable is in scope, then the references are still valid.

It is something else that is causing the values in the hashtable to be
null.

The only things I can think of are that the value at Class1[index] is
already null, and it's null when it goes in, or there is an explicit setting of the value for that key to null.

Can you provide a sample project which shows the error?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roger Webb" <rw***@nos.twia.org> wrote in message
news:Oq**************@TK2MSFTNGP10.phx.gbl...
Hey All,

I cant VERIFY this, but it makes sense so I thought I'd trow up my theory and see if it made sense to any of you... and then ask how to get around
it.
hehe

I've got a Class1[] that I'm wanting to load into a hash table, so, I
basically (at this point) run through a loop and do a
Hashtable.Add(Class1[index].key,Class1[index])

However, later when I try to get out the value out of the HashTable... The value is null.

I'm thinking this is because the array that initially had the values has
gone out of scope .. and the hashtable only stored a reference to the
object.. so now, the refence is null. If this is true, how do I get
around that? If it is not true, does anyone know why I'm not getting my
values out?

- Roger


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Stockwell | last post by:
Hi, Another of my crazy questions. I'm just in the process of learning so bear with me if you can. I actually ran it.... with two test cases TEST CASE 1: Say I have the following defined:...
1
by: Curtis | last post by:
Does anyone know the proper method to save information to embedded hashtables. I am trying to save parent/child information to hashtables but I am not getting the correct results I have made a...
9
by: NevilleDNZ | last post by:
Can anyone explain why "begin B: 123" prints, but 456 doesn't? $ /usr/bin/python2.3 x1x2.py begin A: Pre B: 123 456 begin B: 123 Traceback (most recent call last): File "x1x2.py", line 13,...
17
by: Chad | last post by:
The following question stems from Static vs Dynamic scoping article in wikipedia. http://en.wikipedia.org/wiki/Scope_(programming)#Static_versus_dynamic_scoping Using this sites example, if I...
2
by: PAzevedo | last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from multiple threads, now the Hashtable object is thread safe for reading, but not for writing, so I lock the object every time I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.