Hi.. I wrote following code. -
iindex = 0;
-
foreach (XmlNode Labelnodes1 in Labelnode)
-
{
-
countlab = Labelnodes1.Attributes.Count;
-
for (int i = 0; i < countlab; i++)
-
{
-
-
String temp2 = Labelnodes1.Attributes[i].Name;
-
String temp1 = Labelnodes1.Attributes[i].InnerText;
-
Proplabval.Add(temp2, temp1);
-
}
-
Proptablab.Add(iindex, Proplabval);
-
Proplabval.Clear();
-
iindex++;
-
}
-
I am basically trying to add hash table in hash table.
My for loop(line no 5) will create a hash table.
And it is added to a hash table in for each loop(line no 2)....
Both string temp2,temp1 has correct values..... But when i come out of for each loop my hash table Proptablab do not contain anything....
When i put a break point at line no 12... For all entries it shows the same values.. ie value 1 is same as value2 and equal to value3...
5 2143 PRR 750
Recognized Expert Contributor
You are clearing "Proplabval " line no 13. Debug the code and see if the attributes are added properly ...
I took the Hash tables as class members.. When i put them in my member function. The value is persisting when i come out of the code.....
Regards
Dheeraj Joshi
You are right... Even i have to comment the clear part......
But another observation.. When it was class member(Hash table)and clear was commented... it was giving same problem.. When i bring it in function and commented clear part, it worked fine..
Regards
Dheeraj Joshi
GaryTexmo 1,501
Recognized Expert Top Contributor
The clear there is correct... and not correct. That is, the idea is right, but the implementation is wrong.
You've actually got two hash tables there, one storing attribute names and values, and another storing that hash table in another hash table using an incrementing value (iindex) as the key.
I see what you're trying to do... you want to make sure you're only adding the attributes for that particular node into Proptablab so you clear Proplabval each time you go through, but what you may not have realized is that almost everything except simple value types (ie, int, float, double, etc...) is a reference type.
So you're throwing Proplabval into Proptablab, then clearing it right after, so you're going to have the empty hash table, which is what you're seeing. What you need to do is create a new hash table for the inner loop... I'll modify your code. - // This code would have been wherever you defined these two HashTables
-
HashTable Proptablab = new HashTable();
- //HashTable Proplabval = new HashTable(); // Do this in the loop now
-
...
-
iindex = 0;
-
foreach (XmlNode Labelnodes1 in Labelnode)
-
{
-
HashTable Proplabval = new HashTable();
-
countlab = Labelnodes1.Attributes.Count;
-
for (int i = 0; i < countlab; i++)
-
{
-
String temp2 = Labelnodes1.Attributes[i].Name;
-
String temp1 = Labelnodes1.Attributes[i].InnerText;
-
Proplabval.Add(temp2, temp1);
-
}
-
-
Proptablab.Add(iindex, Proplabval);
-
//Proplabval.Clear(); //This can actually be removed
-
iindex++;
-
}
Give that a try :)
Hey GaryTexmo....
I already Got the solution.. I did same thing as you told... It is working fine...
Thanks for the inputs....
You are right, i almost forgot about the references... I was so stupid when i coded it...
Regards
Dheeraj Joshi
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Pelo GANDO |
last post by:
Hi everybody !
I am a beginner in C++. I am looking for a (simple if it's possible) source
code in C++ about hash table...
Thank you !
Pelo
|
by: VK |
last post by:
Hello,
In my object I have getDirectory() method which returns 2-dimentional
array
(or an imitation of 2-dimentional array using two JavaScript objects
with auto-handled length property - please let's us do not go into an
"each dot over i" clarification discussion now - however you want to
call - you call it ;-)
array contains records of all files in the current dir.
array contains records of all subs in the current dir
|
by: wxs |
last post by:
Many times we have a bunch of enums we have from either different enums or
the same enum that will have various numeric values assigned. Rarely will
there be collisions in numbering between the enums. These enums you might
imagine would be like OrderPrice=27, OrderQuantity=50, OrderSide=62. There
may be a lot of these. So normally what we would have to do is store these
in hash table so hashtable=value could be set with the value....
|
by: Johan Tibell |
last post by:
I would be grateful if someone had a minute or two to review my hash
table implementation. It's not yet commented but hopefully it's short
and idiomatic enough to be readable. Some of the code (i.e. the
get_hash function) is borrowed from various snippets I found on the
net. Thee free function could probably need some love. I have been
thinking about having a second linked list of all entries so that the
cost of freeing is in proportion to...
|
by: gokkog |
last post by:
Hi there,
There's a classic hash function to hash strings, where MULT is defined
as "31":
//from programming pearls
unsigned int hash(char *ptr)
{ unsigned int h = 0;
unsigned char *p = ptr;
| |
by: ababeel |
last post by:
Hi
I am using a calloc in a hash table program on an openvms system. The
calloc is used to declare the hash table
char **pHashes;
pHashes = calloc(hash_size,sizeof(char *)); //hash_size = 101
and then later on when it is half full i do the following
char **newHashes;
if(newHashes)
|
by: ravi |
last post by:
Hi
can anybody tell me that which ds will be best suited to implement a
hash table in C/C++
thanx. in advanced
|
by: Alexander Mahone |
last post by:
Hello, I'm looking for an hash function to be used for an hash table
that will contain structs of a certain kind. I've looked into
Sourceforge.net, but so far I've found only hash functions for strings
(string->index)...Do you know if there exist such a function
somewhere?
Thanks
|
by: raylopez99 |
last post by:
A quick sanity check, and I think I am correct, but just to make
sure: if you have a bunch of objects that are very much like one
another you can uniquely track them simply by using an ArrayList or
Array, correct? An example: create the object, create an array, the
stuff the object into the array. Later on, assume the object is
mutable, the object changes, but you can find it, if you have enough
state information to uniquely identify...
|
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...
|
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,...
| |
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...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |