IsNothing versus Is Nothing

后端 未结 9 1508
暗喜
暗喜 2020-11-29 23:51

Does anyone here use VB.NET and have a strong preference for or against using IsNothing as opposed to Is Nothing (for example, If IsNothing(a

相关标签:
9条回答
  • 2020-11-30 00:14

    I agree with "Is Nothing". As stated above, it's easy to negate with "IsNot Nothing".

    I find this easier to read...

    If printDialog IsNot Nothing Then
        'blah
    End If
    

    than this...

    If Not obj Is Nothing Then
        'blah
    End If
    
    0 讨论(0)
  • 2020-11-30 00:18

    Is Nothing requires an object that has been assigned to the value Nothing. IsNothing() can take any variable that has not been initialized, including of numeric type. This is useful for example when testing if an optional parameter has been passed.

    0 讨论(0)
  • 2020-11-30 00:20

    I'm leaning towards the "Is Nothing" alternative, primarily because it seems more OO.

    Surely Visual Basic ain't got the Ain't keyword.

    0 讨论(0)
提交回复
热议问题