如何在 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"];
}

Mango 现在提供了 MSSqlCE 支持,但对于一组值来说,这有点矫枉过正。如果您需要存储关系数据,而不是持久化用户/应用程序设置,则数据库更合适。

虽然IsolatedStorage 很好,但读取和写入可能很昂贵。避免从您的 UI 线程中读取 IndependentStorage,这会导致您的应用程序看起来没有响应。

关于windows-phone-7 - 使用本地数据库在 Windows Phone 7 中保存变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6951131/

10-11 00:33