这样我需要了解我的内容是否为空,
如果它是空的,它必须简单地下去到详细但如果它不是空的那么标记就是如果
if (long.Parse(HttpContext.Current.Request["subscriptionid"]) != null)
{
_subscriptionId = long.Parse(HttpContext.Current.Request["subscriptionid"]);
}
else
{
_subscriptionId = long.Parse(reader["abonnementsId"].ToString());
}
当我在if语句中鼠标悬停时,会说:
表达式的结果总是“真”,因为“long”类型的值永远不等于long类型的“null”?
答案 0 :(得分:2)
在解析之前,您必须先检查HttpContext.Current.Request["subscriptionid"]
<{1>} 。如果您执行null
,则会返回value type (长),但不能为空,因此会发出警告。
long.Parse
答案 1 :(得分:1)
该消息说明含义:long
类型不是null
,如果不是Nullable type。在你的情况下,它可能足够
if (HttpContext.Current.Request["subscriptionid"] != null)
{
....
}
如果需要,请在执行转换为null
后首先检查long
。
答案 2 :(得分:0)
long
值永远不会null
,long.Parse()
永远不会返回null。您可以使用long.TryParse()
:
long _subscriptionId;
if (long.TryParse(HttpContext.Current.Request["subscriptionid"],out _subscriptionId))
{
...
}