Iterate ArrayList using indexing : ArrayList « Collections « Visual C++ .NET






Iterate ArrayList using indexing

 
#include "stdafx.h"
using namespace System;
using namespace System::Collections;

int main()
{
   ArrayList^ array_list = gcnew ArrayList();

   array_list->Add("apple");
   array_list->Add("banana");


   for each (String^ s in array_list)
   {
       Console::WriteLine( s );
   }


   for (int i = 0; i < array_list->Count; i++)
   {
       Console::WriteLine("{0} {1}", i, array_list[i]);
   }
}

   
  








Related examples in the same category

1.Sort an ArrayList
2.Adding to the end of an ArrayList
3.Adding value to ArrayList with Indexer
4.Insert value to an ArrayList at specified position
5.Using AddRange to add an array of value to ArrayList
6.Reverse the values in an ArrayList
7.Using for loop the display elements in an ArrayList
8.Get the capacity of an ArrayList
9.Set the capacity
10.Get the element count
11.Does an ArrayList contain a value
12.Sort an ArrayList by functor
13.Binary search an ArrayList by functor
14.Adding strings to ArrayList
15.Iterate ArrayList using the for each operator