• Advertisement

Archived

This topic is now archived and is closed to further replies.

MC++ ArrayList, accessing elements

This topic is 5059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#using <mscorlib.dll>

using namespace System;
using namespace System::Collections;

int main()
{
	ArrayList *list = new ArrayList();
	list->Add(__box(54));
	list->Add(__box(32));
	Console::WriteLine(S"The first value is {0} and the second is {1}.", 
						/* what to write here */, /* and here */ );
}
I have tried list[0] and *list, but that doesn''t work. How do you access the elements?

Share this post


Link to post
Share on other sites
Advertisement
You can use the property syntax as well:

theList->Item[5];


Only the indexer-style like in C# (theList[5]) does not work.

Regards,
Andre (VizOne) Loker

Share this post


Link to post
Share on other sites
You should also delete the ArrayList when done. You never call delete on it. I know C# has garbage collection, but it''s a bad habbit to not clean memory. What if the application would run 24/7 and allocation memory in a loop?

Toolmaker



-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites
quote:
Original post by Toolmaker
You should also delete the ArrayList when done. You never call delete on it. I know C# has garbage collection, but it''s a bad habbit to not clean memory. What if the application would run 24/7 and allocation memory in a loop?

Don''t program much Managed C++ do you? Calling delete on an ArrayList pointer will generate a compiler error.

Share this post


Link to post
Share on other sites

  • Advertisement