![](/img/trans.png)
[英]C#: KeyNotFoundException: The given key was not present in the dictionary
[英]Xamarin.Forms - KeyNotFoundException: The given key was not present in the dictionary C#
我正在使用 Xamarin.Forms 並且收到此錯誤:
KeyNotFoundException: 字典中不存在給定的鍵
對於這一行:
bool isLogin = (bool)Application.Current.Properties["isLogin"];
我試圖檢查密鑰是否存在,如下所示:
if(Application.Current.Properties.ContainsKey("isLogin"))
{
bool isLogin = (bool)Application.Current.Properties["isLogin"];
string username = Application.Current.Properties["username"].ToString();
if (isLogin)
{
Application.Current.MainPage.Navigation.PushAsync(new MenuPage(), true);
}
}
但是即使在設置了鍵和值之后,檢查鍵也總是返回 false:
Application.Current.Properties["isLogin"] = true;
即使您終止應用程序並重新啟動它,Application.Current.Properties 也將存在。 只需嘗試以這種方式拔下您的設備並嘗試登錄並檢查,它就會工作。 調試時它不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.