tags:

views:

225

answers:

3

Is this supported in C++ CLI? I want to do something like the following C# example in C++ CLI

var dictionary = new Dictionary<string, string> { { "foo", "bar" } };

Thanks

A: 

Unless I'm horribly mistaken, this is simply not possible.

Maximilian
A: 

It is definitely going to be possible in C++0x, whether that translates to C++/CLI or not is unknown (it should do).

DanDan
+1  A: 

The best I came up with was creating an array initialized inline, then initializing the dictionary with the contents of the array in a static constructor. Something like

static initonly System::Collections::Generic::Dictionary<System::String^, System::String^>^ dictionary;
static initonly array<System::String^> arrayToPopulateDictionary = gcnew array<System::String^> { "foo", "bar" };

static Foo()
{
    for (int i  = 0; i < arrayToPopulateDictionary->Length; i += 2)
  listMappings->Add(arrayToPopulateDictionary[i], arrayToPopulateDictionary[i + 1]));
}