C # Possible inadvertent link comparison

When I try to check Session["userId"] != nullwhy I get this message Possible unintended reference comparrison; to get value comparrison; cast left hand side to stringAny suggestion ....

+5
source share
3 answers

Session[key]returns an object , not a string - you should distinguish it from a string, and not rely on implicit casting or the ToString () function.

+8
source
        if(Session["userId"]!=null)
        {

        }

works great for me

+1
source
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. * /

0
source

All Articles