2009-12-17 66 views

回答

2

我想到的最好的方法是創建一個內聯初始化的數組,然後用靜態構造函數中的數組內容初始化字典。類似於

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

除非我弄錯可怕,這是根本不可能的。

0

C++0x中肯定會有可能,無論是否轉換爲C++/CLI是未知的(它應該這樣做)。