0

I am using the following to check a number of session variables:

if(MySession.Current.mpr != null && MySession.Current.mpr1 != null && MySession.Current.mpr2 != null
  && MySession.Current.mpr3 != null && MySession.Current.mip != null && MySession.Current.vr != null)
{
  ....
}

It does not work! I know one of the variables is not null. Any suggestions?

4

1 回答 1

3

if如果所有变量都不是,则您的语句仅写入块内部null。如果一个变量不为空,要进入内部,请使用 ors||而不是 and &&

if(MySession.Current.mpr != null || MySession.Current.mpr1 != null || MySession.Current.mpr2 != null
  || MySession.Current.mpr3 != null || MySession.Current.mip != null || MySession.Current.vr != null)
{
  ....
}
于 2013-05-06T03:24:09.073 回答