Or versus OrElse

前端 未结 8 1652
感情败类
感情败类 2020-11-27 04:33

What\'s the difference between or and OrElse?

if temp is dbnull.value or temp = 0

produces the error:

8条回答
  •  心在旅途
    2020-11-27 04:48

    OrElse is a short-circuiting operator, Or is not.

    By the definition of the boolean 'or' operator, if the first term is True then the whole is definitely true - so we don't need to evaluate the second term.

    OrElse knows this, so doesn't try and evaluate temp = 0 once it's established that temp Is DBNull.Value

    Or doesn't know this, and will always attempt to evaluate both terms. When temp Is DBNull.Value, it can't be compared to zero, so it falls over.

    You should use... well, whichever one makes sense.

提交回复
热议问题