更新时间:2023-11-04 23:00:52
第二个:
this.isLoggedIn = (bool)HttpContext.Current.Session["li"];
(布尔)HttpContext.Current.Session [礼]
已经是一个布尔值(所以会为真正
或假
),因此无需为布尔前pression额外的比较和返回值。
(bool)HttpContext.Current.Session["li"]
is already a boolean (so will be either true
or false
), so no need for the extra comparison and return value of the boolean expression.
无论哪种方式,你需要检查里
会话变量尝试投放之前存在,或者您的code将抛出(我觉得的NullReferenceException
)。
Either way, you need to check that the li
session variable exists before trying to cast it, or your code will throw (I think a NullReferenceException
).