Mega Code Archive

 
Categories / Visual C++ .NET / Collections
 

Using for each to loop through a dictionary

#include "stdafx.h" #using <system.dll> using namespace System; using namespace System::Collections::Generic; void main() {     Dictionary<int,String^>^ dict = gcnew Dictionary<int,String^>();     dict->Add(1,  "One");     dict->Add(6,  "Six");     dict->Add(5,  "Five");     dict->Add(3,  "3");     dict[3] = "Three";     dict[7] = "Seven";              for each (KeyValuePair<int,String^>^ pair in dict)     {         Console::WriteLine("Key = [{0}]\tValue = [{1}]", pair->Key, pair->Value);     }      }