不适用于 Windows Phone ,应用设置存储 引用using Windows.Storage

network | | 访问(58)
// 根据对应的键获取值
public T GetDataContainerValue < T > (string key) {
    T value = default(T);
    // 应用设置存储 引用using Windows.Storage;
    ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
    ApplicationDataContainer container = localSettings.CreateContainer("SettingsContainer", ApplicationDataCreateDisposition.Always);
    if (localSettings.Containers.ContainsKey("SettingsContainer") && !string.IsNullOrEmpty(key)) {
        value = (T) localSettings.Containers["SettingsContainer"].Values[key];
    }
    return value;
}

// 根据对应的键设置值
public void SetDataContainerValue < T > (string key, T value) {
    // 应用设置存储 引用using Windows.Storage;
    ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
    ApplicationDataContainer container = localSettings.CreateContainer("SettingsContainer", ApplicationDataCreateDisposition.Always);
    localSettings.Containers["SettingsContainer"].Values[key] = value;
}