2015-09-17 58 views
0

我正在將一箇舊遊戲移植到Windows 10商店應用程序。 我可以寫,然後讀字符串應用程序設置:如何將整數序列化到ApplicationDataContainer

ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings; 

localSettings->Values->Insert("keyS", "hello"); 
String^ valueS = safe_cast<String^>(localSettings->Values->Lookup("keyS")); 

我也可以把int值:

localSettings->Values->Insert("keyI", 123); 

但是我怎麼看它?

??? valueI = safe_cast<???>(localSettings->Values->Lookup("keyI")); 

Lookup回報Platform::Object^,所以我怎麼將其轉換爲int

回答

1

它是一個IBox - 相當於.NET中的「可空」。

auto localSettings = ApplicationData::Current->LocalSettings; 
localSettings->Values->Insert(L"forty-two", (int)42); 
auto forty_two = static_cast<Platform::IBox<int>^> 
    (localSettings->Values->Lookup(L"forty-two")); 
if (forty_two != nullptr) 
{ 
    int value = forty_two->Value; 
    // use value 
}