Mega Code Archive

 
Categories / Visual C++ .NET / Collections
 

Pass Dictionary to a function

#include "stdafx.h" #using <system.dll> using namespace System; using namespace System::Collections::Generic; ref class Reverse : public IComparer<int>{ public:     virtual int Compare(int x, int y) { return y - x; }     virtual bool Equals(int x, int y) { return x == y; }     virtual int GetHashCode(int obj) { return obj.GetHashCode(); } }; void SortedDictionaryExample(Dictionary<int,String^>^ inDict) {     SortedDictionary<int,String^>^ dict = gcnew SortedDictionary<int,String^>(inDict, gcnew Reverse());          dict->Add(6,  "Six");     String^ t = dict[3];     Console::WriteLine("dict[3] = {0}\n", t); } 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";              SortedDictionaryExample(dict);      }