C# Possible unintended reference comparison
When i try to check Session["userId"] != null
why i get this message Possible unintended reference comparrison; to get value comparrison; cast le开发者_开发技巧ft hand side to string
Any suggestion....
Session[key]
returns an object, not a string - you should be casting it to string rather than relying on implicit casting or ToString() functionality.
if(Session["userId"]!=null)
{
}
works just fine for me
if (String.IsNullOrEmpty(s)) {
return "is null or empty";
}
else{
return String.Format("(\"{0}\") is not null or empty", s);
}
/* true if the value parameter is null or an empty string (""); otherwise, false. */
精彩评论