Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting variable having found it in a HashTable search

Status
Not open for further replies.

tobriain

Programmer
Jul 19, 2006
13
IE
I'm connecting to an external program to register for some updates to some values. The external program periodically returns updates to a method in my class. I submit a reference id when registering for all the different updates, and the external program returns the reference id I submitted and the relevant update. My problem is this. . .

When I get the update (with the reference id as a string also returned to me), if I search a hastable that has the reference id as a KEY, can I directly set the relevant variable by putting it in as the VALUE part of the Hashtable? Which other way could I do this, because if I have to hard code multiple Switch statements to implement it, I'll have lots of duplicate coding etc.

Here are some code snippets of what I'd like to implement:

Int Price = 0;
. . . .. . . . . . .. .
Hashtable TopicsForRegistering = new Hashtable();
TopicsForRegistering["PRICE"] = Product.Price;
. . . . . ... . . . .
[I have to implement this interface here. . ]
ExtProg.RegisterForUpdates("PRICE", , ,, , ,,, ,)
. . . . . . .. . . . .
[I have to implement this interface here also. .I collect an array with two columns and one row]
System.Array Updates = ExtProg.CollectUpdates();
int ReferenceID = Convert.ToInt32(Updates.GetValue(0,0);
int UpdateValue= Convert.ToInt32(Updates.GetValue(1,0);
TopicsForRegistering [ReferenceID] = UpdateValue;
[At this point, I'd like the value of the original Product.Price to have changed, not just the value in the Hashtable. . . . ]

I'd appreciate any help at all on this.

Best regards,

Tom.
 
It should work, as the Hashtable is returning you a reference to the object that was stored in the Value part of the hash. IOW, it should point to the same memory address as before.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
OK. I understand I can change the value in the hashtable, but how can I change the original variable 'Price', using the reference in the hashtable?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top