Visual C++ .NET/Generics/Generic List — различия между версиями

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

Версия 15:31, 26 мая 2010

generic List

 
#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]);
   }
}


Iterate generic list using the for each operator

 
#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]);
   }
}


Iterate generic list using the 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]);
   }
}


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]);
   }
}


Iterate List using the for each operator

 
#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]);
   }
}