473,560 Members | 3,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

generic reset of values for hashtable

I have a reason to resuse hashtables and I'd like to set the values to null
without having to reload the keys.- > which is what the clear method does.

If I try a foreach construct I get an error that I cannot alter the value.
The documentation for using an enumerator and moveNext also have the same
restriction.

WONT WORK:
private Hashtable hashValueNuller (Hashtable theHash)
{
foreach (DictionaryEntr y dObj in theHash)
{
dObj.Value = null;
}
return theHash;
}

Is the only way out of this to use a clear and constructor takling an array
of keys ?

--
Andrew
Jan 27 '06 #1
2 2644
Andrew,
Have you tried to use a foreach over the keys of the Hashtable?

Something like:

static private Hashtable hashValueNuller (Hashtable theHash)
{
object[] keys = new object[theHash.Keys.Co unt];
theHash.Keys.Co pyTo(keys, 0);
foreach (object key in keys)
{
theHash[key] = null;
}
return theHash;
}

Note a copy of the keys is made, as changing a key's value is considered a
change to the Hashtable.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"andrewcw" <an******@acw.c om> wrote in message
news:5C******** *************** ***********@mic rosoft.com...
|I have a reason to resuse hashtables and I'd like to set the values to null
| without having to reload the keys.- > which is what the clear method does.
|
| If I try a foreach construct I get an error that I cannot alter the
value.
| The documentation for using an enumerator and moveNext also have the same
| restriction.
|
| WONT WORK:
| private Hashtable hashValueNuller (Hashtable theHash)
| {
| foreach (DictionaryEntr y dObj in theHash)
| {
| dObj.Value = null;
| }
| return theHash;
| }
|
| Is the only way out of this to use a clear and constructor takling an
array
| of keys ?
|
| --
| Andrew
Jan 27 '06 #2
Thanks !!! - I dont know hoe long it would have taken me to think of that !
It works perfectly.
--
Andrew
"Jay B. Harlow [MVP - Outlook]" wrote:
Andrew,
Have you tried to use a foreach over the keys of the Hashtable?

Something like:

static private Hashtable hashValueNuller (Hashtable theHash)
{
object[] keys = new object[theHash.Keys.Co unt];
theHash.Keys.Co pyTo(keys, 0);
foreach (object key in keys)
{
theHash[key] = null;
}
return theHash;
}

Note a copy of the keys is made, as changing a key's value is considered a
change to the Hashtable.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"andrewcw" <an******@acw.c om> wrote in message
news:5C******** *************** ***********@mic rosoft.com...
|I have a reason to resuse hashtables and I'd like to set the values to null
| without having to reload the keys.- > which is what the clear method does.
|
| If I try a foreach construct I get an error that I cannot alter the
value.
| The documentation for using an enumerator and moveNext also have the same
| restriction.
|
| WONT WORK:
| private Hashtable hashValueNuller (Hashtable theHash)
| {
| foreach (DictionaryEntr y dObj in theHash)
| {
| dObj.Value = null;
| }
| return theHash;
| }
|
| Is the only way out of this to use a clear and constructor takling an
array
| of keys ?
|
| --
| Andrew

Jan 27 '06 #3

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

Similar topics

4
1483
by: Job Lot | last post by:
On form load my datagrid gets populated with values from database table. How can I reset values in my DataGrid to 0 on click of a button? thanks
8
59508
by: SenthilVel | last post by:
how to get the corresponding values for a given Key in hashtable ??
5
1371
by: Bernie V | last post by:
Hi group, I have a waebform to send emails. On the form there are 2 buttons: A button "send" and a button "reset". If I click aon the button my email is send, but I want to reset the values on my form (to send another email). How can I do that. ?
4
2190
by: drago | last post by:
Hi guys, I will be quick this time... Just want to know how we can calculate generic values in the same column. I am using invoice form with a services subform . I have a column of 'total' in subform and I want to add all values of that column to get the total cost on main invoice form. The 'total' column contains service cost of different...
2
1261
by: Pankaj Upmanyu | last post by:
Hi, I need to know how to reset values in 40 textboxes in one go. Mind I am using 8 arrays of text boxes. Please help how to validate them for a rage of values. I am a new learner. Thanks Pankaj
16
2073
by: Giovanni D'Ascola | last post by:
Hi. I noticed that <input type="reset"actually don't enable checkbutton which are checked by default after they have been disabled by javascript. It's a bug?
7
1842
by: bkendra5 | last post by:
I am building a db, and I have 3 different tables/forms that I need to transfer records between. Current Clients, Past Clients, and Prospective. Now i have researched this for almost a week now, and i found similar posts, but no one every says how they resolved them. What I am doing: I have in each table a yes/no that is called Append. I made...
5
4593
by: Anders Borum | last post by:
Hi! While implementing a property manager (that supports key / value pairs), I was wondering how to constrain T to a struct or string type. Basically, I guess what I'm looking for is the common denominator for structs and strings and while looking through the SDK I only noticed the IEquatable<T> interface. So I implemented the class with...
1
1440
by: thesti | last post by:
hello, i have a hashTable of which values are needed to be reset. i've tried using the DictionaryEntry to iterate through each element in the hashTable and setting their values to 0, but it seems that it doesn't work. For Each item As DictionaryEntry In hashQty item.Value = 0 Next
0
7557
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7849
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8070
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7603
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7922
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6194
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5176
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1171
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.