var page
是我从用户中获得的文本框。从var page
我完成了以下代码。
希望您从代码中理解,所以我无需再详细解释。
当我使用page
if condition
时,会显示错误。怎么摆脱那个?
代码;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.ContainsKey("Page"))
{
var page = NavigationContext.QueryString["Page"];
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("qsPage"))
{
settings.Add("qsPage", page);
}
else
{
settings["qsPage"] = page;
yourWebBrowser.Navigate(new Uri("/f" + page + ".html", UriKind.Relative));
}
}
代码给出错误;
private void def(object sender, EventArgs e)
{
int num = 0;
var page = IsolatedStorageSettings.ApplicationSettings["qsPage"];
if (int.TryParse(page, out num) && num > 0 && num < 455)
{
// .... //
}
}
错误 -
Error 1: Argument 1: cannot convert from 'object' to 'string'
Error 2: The best overloaded method match for 'int.TryParse(string, out int)' has some invalid arguments
答案 0 :(得分:0)
var page = (string)IsolatedStorageSettings.ApplicationSettings["qsPage"];
答案 1 :(得分:0)
var page = IsolatedStorageSettings.ApplicationSettings["qsPage"] as string;
if (page != null && int.TryParse(page, out num) && num > 0 && num < 455)
...