开发者

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. */

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜