Which is better for performance? And vs AndAlso

后端 未结 3 492
梦谈多话
梦谈多话 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:43

    When the conditions are also functions:

    If functionA() And functionB() Then
    

    ...

    public shared functionA() As Boolean
      IF A is false THEN log -> return true or false
    

    ...

    public shared functionB() As Boolean
      IF B is false THEN log -> return true or false
    

    Using AndAlso here could be the wrong way to go, because then it will only log B when both A and B are false.

提交回复
热议问题