MC++ ArrayList, accessing elements

Started by
4 comments, last by Eriond 20 years, 1 month ago
#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?
Advertisement
Did you try list->get_Item(0); ?
Thank you, don''t know how I missed that.
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
Andre Loker | Personal blog on .NET
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.

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.

This topic is closed to new replies.

Advertisement