Is there a VB.net equivalent for C#'s ! operator?

前端 未结 6 1762
旧巷少年郎
旧巷少年郎 2020-12-19 14:02

After two years of C#, I\'m now back to VB.net because of my current job. In C#, I can do a short hand testing for null or false value on a string variable like this:

<
6条回答
  •  萌比男神i
    2020-12-19 14:47

    Not is exactly like ! (in the context of Boolean. See RoadWarrior's remark for its semantics as one's complement in bit arithmetic). There's a special case in combination with the Is operator to test for reference equality:

    If Not x Is Nothing Then ' … '
    ' is the same as '
    If x IsNot Nothing Then ' … '
    

    is equivalent to C#'s

    if (x != null) // or, rather, to be precise:
    if (object.ReferenceEquals(x, null))
    

    Here, usage of IsNot is preferred. Unfortunately, it doesn't work for TypeOf tests.

提交回复
热议问题