Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vb.net

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:

if(!String.IsNullOrEmpty(blah))
{
   ...code goes here
}

however I'm a little confused about how to do this in VB.net.

if Not String.IsNullOrEmpty(blah) then
   ...code goes here
end if

Does the above statement mean if the string is not null or empty? Is the Not keyword operate like the C#'s ! operator?

like image 662
Jack Avatar asked Nov 27 '22 10:11

Jack


2 Answers

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:

  • logical negation: !
  • bitwise complement: ~

For example, the following two lines are equivalent:

  • C#: useThis &= ~doNotUse;
  • VB: useThis = useThis And (Not doNotUse)
like image 123
HTTP 410 Avatar answered Feb 05 '23 17:02

HTTP 410


Yes they are the same

like image 44
Ruben Avatar answered Feb 05 '23 17:02

Ruben