Or versus OrElse

前端 未结 8 1627
感情败类
感情败类 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:43

    Unless your code logic requires the short-circuiting behavior OrElse provides, I would lean toward using the Or operator because:

    • Using "Or" is simple and requires less typing.
    • The computational time savings of using OrElse is negligible in most cases.
    • Most importantly, using OrElse can hide errors in later clauses that may not be initially revealed until those conditions would eventually be met by the program logic.

提交回复
热议问题