C++ CLI Collection initializer syntax

牧云@^-^@ 提交于 2019-12-05 22:50:38

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

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!