473,804 Members | 3,473 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 2657
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
1496
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
59520
by: SenthilVel | last post by:
how to get the corresponding values for a given Key in hashtable ??
5
1380
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
2201
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 clients. Some clients have 1 service i.e 1 total which is the total cost but most clients have more then 1...
2
1271
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
2088
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
1855
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 an append query, that upon Yes, it will append 1 record, then i have manually delete it from the...
5
4616
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 methods such as the following, but I'm aware that this is not the right approach.
1
1450
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
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9138
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5516
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
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.