我試圖在應用程序第一次啓動時設置一些默認設置。我嘗試和檢測當字符串等於null,但它一直拋出異常錯誤,有什麼想法?當String等於NULL時發生異常錯誤
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
String isFirstRun = settings["firstrun"] as string;
if (isFirstRun == null)
{
settings["firstrun"] = "no";
settings["defaultLocation"] = "Dulles, VA";
settings["defaultTest"] = "Speed Test";
settings.Save();
}
}
異常錯誤是:
MyConnection.DLL MyConnection.App.RootFrame_NavigationFailed(對象發件人,System.Windows.Navigation.NavigationFailedEventArgs E)線103 C#
在嘗試將其轉換爲字符串之前,首先檢查'settings [「firstrun」]是否爲'null'。更好的是,不要拋棄它...... – Liel
「但它一直拋出一個異常錯誤」 - 正是什麼異常? –
我已經從問題標題中刪除標籤 - 請注意比大多數情況下的問題[不應在標題中包含標籤](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-在-其-標題)。 – Romasz