简体   繁体   English

如何将IsolatedStorageSettings密钥保存到字符串

[英]How to save IsolatedStorageSettings key to a string

I'm making a project for windows phone 8 using C# and I want to be able to save some strings to storage so the next time the user opens the app, He'll be able to have the strings he saved last time he opened it. 我正在使用C#为Windows Phone 8创建一个项目,并且希望能够将一些字符串保存到存储中,因此下一次用户打开该应用程序时,他将能够使用上次打开该应用程序时保存的字符串。

I set it like this: 我这样设置:

IsolatedStorageSettings.ApplicationSettings["key"] = SetKey.Text;

and I try to get it like this: 我试图这样得到它:

if (IsolatedStorageSettings.ApplicationSettings.Contains("key"))
{
    string GetKey = (string)IsolatedStorageSettings.ApplicationSettings["key"];
}

SetKey is the name of a TextBox. SetKey是文本框的名称。

The problem is that when I run this I get an unhandled exception at the code line that is in the if, saying: 问题是,当我运行此代码时,在if的代码行中收到未处理的异常,说:

An exception of type 'System.InvalidCastException' occurred in ProjectName.DLL but was not handled in user code. ProjectName.DLL中发生类型'System.InvalidCastException'的异常,但未在用户代码中处理。

if (IsolatedStorageSettings.ApplicationSettings.Contains("key") && 
        IsolatedStorageSettings.ApplicationSettings["key"] != null)
{
    string GetKey = IsolatedStorageSettings.ApplicationSettings["key"].ToString();
}

Try like this ! 尝试这样! Probably key is null. key可能为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM