我想使用'if'循环检查整数值是否为零或其他整数。我这样做了
int ID = (int)Session["id"];//I have assigned Session["id"]=20; on previous page
if (ID == 0 || ID =50)
Response.Redirect("Login.aspx");
但它显示错误运算符'||'不能应用于'bool'和'int'类型的操作数。请帮忙
答案 0 :(得分:6)
您要为ID分配50 ..不比较......应该是
if (ID == 0 || ID ==50)
答案 1 :(得分:3)
纠正你的if块
if (ID == 0 || ID ==50)
Response.Redirect("Login.aspx");
答案 2 :(得分:3)
你想要这个: -
if (ID == 0 || ID ==50)
^---> //Change here as you are not comparing you are assigning which is not correct as per your need
因为=
表示分配,您想要进行比较。因此,您可能需要使用==
代替=
答案 3 :(得分:0)
您在if块中使用了“=”而不是“==”
if (ID == 0 || ID == 50)
Response.Redirect("Login.aspx");
答案 4 :(得分:0)
我想你错过了那里的==
..
尝试以下。
int ID = (int)Session["id"];//I have assigned Session["id"]=20; on previous page
if (ID == 0 || ID == 50)
Response.Redirect("Login.aspx");