How do I use local database in windows phone 7 to save just a value, then retrieve that value every time the app is loaded (opened)?
问问题
1401 次
1 回答
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 支持,但是对于一组值来说,它是矫枉过正的。如果您需要存储关系数据,而不是持久化用户/应用程序设置,则数据库更合适。
虽然独立存储很好,但读取和写入的成本可能很高。避免从你的 UI 线程中读取 IsolatedStorage,这会导致你的应用看起来没有响应。
于 2011-08-05T03:42:46.353 回答