不能隐式地将类型'int'转换为'string'c#

pur*_*dya -2 c# asp.net

我在我的应用程序中有登录页面,因为我已将我的指定ID保存在Cookies中

Response.Cookies["DesignationID"].Value = ds.Tables[0].Rows[0]["DesignationID"].ToString();
Run Code Online (Sandbox Code Playgroud)

在用户登录之后在另一个页面中我想要检索该cookie值,所以我编写了类似的代码

if (Convert.ToInt32(Request.Cookies["DesignationID"].Value = 2))
Run Code Online (Sandbox Code Playgroud)

但它显示错误,如不能隐式将类型'int'转换为'string'c#,红色虚线在2以下...所以请给我一些提示......

Dav*_*d M 14

你可能应该:

if (Convert.ToInt32(Request.Cookies["DesignationID"].Value) == 2)
Run Code Online (Sandbox Code Playgroud)

所以一个错位的括号,一个赋值而不是相等运算符.或者只是比较字符串:

if (Request.Cookies["DesignationID"].Value == "2")
Run Code Online (Sandbox Code Playgroud)