设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 服务器 > 系统 > 正文

windows-phone-7 – 使用本地数据库在Windows Phone 7中保存变量

发布时间:2021-02-04 09:46 所属栏目:52 来源:网络整理
导读:如何在 Windows Phone 7中使用本地数据库只保存一个值,然后在每次加载(打开)应用程序时检索该值? 解决方法 如果您只想存储一个值进行检索,那么我建议使用IsolatedStorage,尤其是ApplicationSettings类. 它的用法示例: using System.IO.IsolatedStorage;//s

如何在 Windows Phone 7中使用本地数据库只保存一个值,然后在每次加载(打开)应用程序时检索该值?

解决方法

如果您只想存储一个值进行检索,那么我建议使用IsolatedStorage,尤其是ApplicationSettings类.

它的用法示例:

using System.IO.IsolatedStorage;

//storing value
int someValue = 10;
IsolatedStorageSettings.ApplicationSettings.Add("MyKey",someValue);

//write or update value
IsolatedStorageSettings.ApplicationSettings["MyKey"] = someValue;

//write to disk
IsolatedStorageSettings.ApplicationSettings.Save();


//reading value
if(IsolatedStorageSettings.ApplicationSettings.Contains("MyKey"))
{
   int readValue = (int) IsolatedStorageSettings.ApplicationSettings["MyKey"];
}

芒果现在提供MSSqlCE支持,但对于一组值,它是过度的.如果需要存储关系数据,则数据库更合适,而不是持久化用户/应用程序设置.

虽然IsolatedStorage很好,但读取和写入的成本可能很高.避免从UI线程中读取IsolatedStorage,这会导致您的应用看起来没有响应.

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读