如何将整数序列化为ApplicationDataContainer

时间:2015-09-17 16:51:34

标签: windows-store-apps windows-10

我将旧游戏移植到Windows 10商店应用程序。 我可以写,然后读取字符串到应用程序设置:

DoSomething()

我也可以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^

1 个答案:

答案 0 :(得分: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
}