阅读和的Windows Phone 8写入名单IsolatedStorage [英] Read and write list to IsolatedStorage in Windows Phone 8

查看:168
本文介绍了阅读和的Windows Phone 8写入名单IsolatedStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只需保存字符串到独立存储的名单上的Windows Phone 8,我只是创建了一个列表,并保存它是这样的:

I'm trying to simply save a list of strings to isolated storage on windows phone 8. I have simply created a list and save it this way:

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

List<String> projectList = new List<String>();

projectList.add("yo");

settings.add("yo", projectList");

settings.Save();

我如何读IsolatedStorage这些数据,并把它放入同一个列表,一旦应用程序启动再次我在寻找一个简单的方法? - 我还没有找到在网络上,我还没有成功地实现任何我在网上找到的解决方案,因为它们使用不同的方法。

How do i read this data from IsolatedStorage and put it into the same list once the app starts up again? I'm looking for a simple method - which i haven't found on the web, i haven't managed to implement any of the solutions i found on the web, as they use different methods.

请帮忙,非常感谢!

推荐答案

您可以只投的设置回一个名单,我通常会添加一个辅助函数读取设置,以防止阅读的东西未保存的:

You can just cast the setting back into a List. I usually add a helper function to read settings, to prevent reading something that isn't saved:

private static object readSetting(string key)
{
    return IsolatedStorageSettings.ApplicationSettings.Contains(key) ? IsolatedStorageSettings.ApplicationSettings[key] : null;
}

您可以使用该功能来恢复您的清单,比如像这样的:

You could use that function to restore your List, for example like this:

List<String> projectList = readSetting("yo") != null ? (List<String>)readSetting("yo") : new List<String>();

这篇关于阅读和的Windows Phone 8写入名单IsolatedStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆