tomas

tomas

  • NA
  • 7
  • 0

Setting variable having found it in a HashTable search

Feb 20 2008 6:32 AM
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.

Answers (3)