繁体   English   中英

C#可能是非预期的参考比较

[英]C# Possible unintended reference comparison

当我尝试检查Session["userId"] != null为什么我收到此消息Possible unintended reference comparrison; to get value comparrison; cast left hand side to string Possible unintended reference comparrison; to get value comparrison; cast left hand side to string Possible unintended reference comparrison; to get value comparrison; cast left hand side to string任何建议....

Session[key]返回一个对象 ,而不是一个字符串 - 您应该将其转换为字符串,而不是依赖于隐式转换或ToString()功能。

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

        }

对我来说效果很好

if (String.IsNullOrEmpty(s)) {
        return "is null or empty";
}
    else{

        return String.Format("(\"{0}\") is not null or empty", s);
}

/ *如果value参数为null或为空字符串(“”),则为true; 否则,错误。 * /

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM