Which is better of the following?
this.isLoggedIn = (bool)HttpContext.Current.Session["li"] == true;
or
this.isLoggedIn = (bool)HttpContext.Current.Session["li"];
It needs be to true ONLY when the session is true. If the session is set to false will this evaluate to true in #2 as it exists? Or is it evaluating its value?
The second one:
(bool)HttpContext.Current.Session["li"]is already a boolean (so will be eithertrueorfalse), so no need for the extra comparison and return value of the boolean expression.Either way, you need to check that the
lisession variable exists before trying to cast it, or your code will throw (I think aNullReferenceException).