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:
<Yes they are the same
They work identically until you reference C or C++ code.
For example doing NOT on the result of a Win32 API function, might lead to incorrect result, since true in C == 1, and a bitwise NOT on 1 does not equal false.
As 1 is 00000000001 Bitwise Not 11111111110 While false is 00000000000
However in VB it works just fine, as in VB true == -1
As -1 is 11111111111 Bitwise Not 00000000000
c# : boolean example1 = false;
boolean example2 = !example1;
vb.net: dim example1 as boolean = False
dim example2 as boolean = Not example1
Seconded. They work identically. Both reverse the logical meaning of the expression following the !/not operator.
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.
In the context you show, the VB Not keyword is indeed the equivalent of the C# ! operator. But note that the VB Not keyword is actually overloaded to represent two C# equivalents:
!~For example, the following two lines are equivalent:
useThis &= ~doNotUse; useThis = useThis And (Not doNotUse)