错误消息“无法将类型'String'隐式转换为'Int'”

没有人

我不断收到调试错误“无法将类型'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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Unity3D-错误-无法将类型'int'隐式转换为'string'

错误 2 无法将类型“int”隐式转换为“string”c#

C# 返回错误“无法将类型‘int’隐式转换为‘string’”,即使没有给出 int

webservice无法构建-“无法将类型'string'隐式转换为'int'”

无法将类型“string”隐式转换为“int”以比较 2 个变量

无法将类型'int'隐式转换为'string'c#

对于字符串数组,无法将类型“int”隐式转换为“string”

无法将类型'double'隐式转换为'int'。-错误

无法将类型字符串隐式转换为System.Func <string,int,string,string>

无法在2个整数上将类型'int'隐式转换为'string'

无法将类型 'IEnumerable<int> 隐式转换为 'int'

无法将类型int []隐式转换为int?[]

无法将类型'int'隐式转换为'bool'Unity

无法将类型“ double”隐式转换为“ int”

无法将类型“int”隐式转换为“bool”

无法将类型'float'隐式转换为'int'

无法将类型隐式转换为int []

无法将类型“bool”隐式转换为“int”

无法隐式将类型string []转换为string

隐式将NSNumber *转换为int

隐式将int转换为double

C# - 不能将类型“string[][]”隐式转换为“int[][]”

无法将类型'string'隐式转换为'decimal'

Unity无法将类型“ string”隐式转换为“ bool”

无法将类型'string'隐式转换为'bool'[If语句]

无法将类型'string'隐式转换为'integer'

Python:错误“类型错误:无法将 int 隐式转换为 str”

无法将int隐式转换为int []

错误:无法将int类型的表达式...隐式转换为ubyte