Iterate List using indexing : Generic List « Generics « Visual C++ .NET






Iterate List using indexing

 

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

int main()
{
   List<String^>^ list = gcnew List<String^>();

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

   // Iterate using the for each operator.
   for each (String^ s in list)
   {
       Console::WriteLine( s );
   }

   // Iterate using indexing.

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

   
  








Related examples in the same category

1.Iterate generic list using the indexing
2.Iterate generic list using the for each operator
3.Generic list
4.generic List
5.Iterate List using the for each operator