HashTable in C++

carpe2

Freshman
Joined
Jan 16, 2004
Messages
42
Location
Spain
Hi,
I am a C# developer that has to make some code in managed C++. I have to work with HashTable, but I can´t find ways to access items. I would like something like this in C++:

C#
Hashtable myTable = new HashTable();
myTable.Add("Add1", "Test");
myTable.Add("Add2", "Test2");
string test = myTable["Add1"].ToString();

C++
Hashtable *myTable = new HashTable();
myTable->Add("Add1", "Test");
myTable->Add("Add2", "Test2");
?????????????????????????????????


Thanks in advance.
 
get_Item(...) old syntax

I assume you're using .Net 1.x, so you have to use the older syntax. In the case of accessing properties, this means using get_ and set_ methods, like so:

Code:
Hashtable __gc*	myTable = __gc new Hashtable();
myTable->Add(S"Add1", S"Test");
myTable->Add(S"Add2", S"Test2");

String __gc*	test = myTable->get_Item(S"Add1")->ToString();

In .Net 2.0 there is a new syntax which is a little less clumsy.

Good luck :cool:
 
Back
Top