Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Adolfo.
Posted

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:

 

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:

Never trouble another for what you can do for yourself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...