[英]How to save IsolatedStorageSettings key to a string
我正在使用C#为Windows Phone 8创建一个项目,并且希望能够将一些字符串保存到存储中,因此下一次用户打开该应用程序时,他将能够使用上次打开该应用程序时保存的字符串。
我这样设置:
IsolatedStorageSettings.ApplicationSettings["key"] = SetKey.Text;
我试图这样得到它:
if (IsolatedStorageSettings.ApplicationSettings.Contains("key"))
{
string GetKey = (string)IsolatedStorageSettings.ApplicationSettings["key"];
}
SetKey是文本框的名称。
问题是,当我运行此代码时,在if的代码行中收到未处理的异常,说:
ProjectName.DLL中发生类型'System.InvalidCastException'的异常,但未在用户代码中处理。
if (IsolatedStorageSettings.ApplicationSettings.Contains("key") &&
IsolatedStorageSettings.ApplicationSettings["key"] != null)
{
string GetKey = IsolatedStorageSettings.ApplicationSettings["key"].ToString();
}
尝试这样! key
可能为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.