Which is better for performance? And vs AndAlso

后端 未结 3 501
梦谈多话
梦谈多话 2020-12-30 00:50

When writing an If statement, I\'ve always used And when needed like:

If 1=1 And 2=2 Then

The only time I ever used AndA

3条回答
  •  心在旅途
    2020-12-30 01:30

    Coming from a C and C++ background into VB (V5 initially) it was always really annoying that VB's and and or didn't short circuit. So the case where the second expression was dependent on the first was always harder to write.

    I wouldn't expect to see much of a performance increase most of the time, unless the second expression has significant overhead, short circuiting operators will avoid executing it and thus speeding things up.

    But if that second expression is a significant overhead then I would be concerned about side effects which will only be performed sometimes—this will make future maintenance harder and could make correctness harder to maintain.

提交回复
热议问题