Visual C++ .NET/Generics/Generic Array

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Generic array string

<source lang="csharp">

  1. include "stdafx.h"

using namespace System; int main() {

  array<String^>^ stringArray = gcnew array<String^>(5){ "one", "two" };
  for (int i = 0; i < stringArray->Length; i++)
  {
     Console::WriteLine( stringArray[i] );
  }
  Console::WriteLine("End.");

}

 </source>


Integer generic array

<source lang="csharp">

  1. include "stdafx.h"

using namespace System; using namespace System::Collections; void main() {

   array<int>^ IntList = gcnew array<int> { 1, 2, 3, 4, 5 };
   IEnumerable ^collection = (IEnumerable^)IntList;
   IEnumerator ^enumerator = collection->GetEnumerator();
   while (enumerator->MoveNext())
   {
       int i = (int)enumerator->Current;
       Console::WriteLine(i);
   }
   for each (int i in IntList)
       Console::WriteLine(i);

}

 </source>