0

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
4

2 回答 2

0
var page = (string)IsolatedStorageSettings.ApplicationSettings["qsPage"];
于 2013-08-29T14:26:57.103 回答
0
var page = IsolatedStorageSettings.ApplicationSettings["qsPage"] as string;

if (page != null && int.TryParse(page, out num) && num > 0 && num < 455)
...
于 2013-08-29T14:27:26.127 回答