我不断收到调试错误“无法将类型'string'隐式转换为'int'”。
我将出现错误的文本加粗。
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie httpCookie = Request.Cookies["UserInfo"];
if (httpCookie == null)
{
txtDiv.Visible = true;
}
else
{
msgDiv.Visible = true;
string userName = httpCookie.Values["Name"].ToString();
WelcomeLabel.Text = "Welcome Back Mr. "+userName;
}
}
protected void SignupButton_Click(object sender, EventArgs e)
{
// Error in Below Line.
HttpCookie httpCookie = new HttpCookie["UserInfo"];
httpCookie.Values.Add("Name", NameTextBox.Text);
httpCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(httpCookie);
Response.Redirect("Thanks.aspx?name="+NameTextBox.Text);
// Server.Transfer("Thanks.aspx");
}
我还将其更改为新的HttpCookie [“ UserInfo”]。ToString();。但是错误.......
更改HttpCookie httpCookie = new HttpCookie["UserInfo"];
为HttpCookie httpCookie = new HttpCookie("UserInfo");
但是出现'string'到'int'错误的原因[]
是因为它用于数组的索引[int]
。因此,它正在尝试将字符串转换为int类型。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句