possible to use Bang ! notation in place of "Not" keyword?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If Not st1.Equals("something") then
Do Something Else
End If

if str1 != "something" Then ...

I realize that != is C# stuff and/or can be also be used in Tsql, but is
there any implementation of bang ! in VB.Net? Just checking. Any samples
appreciated.

Thanks,
Rich
 
I realize that != is C# stuff and/or can be also be used in Tsql, but
is there any implementation of bang ! in VB.Net? Just checking. Any
samples appreciated.

That's C#.
 
If Not st1.Equals("something") then
Do Something Else
End If

if str1 != "something" Then ...

I realize that != is C# stuff and/or can be also be used in Tsql, but is
there any implementation of bang ! in VB.Net? Just checking. Any samples
appreciated.

Thanks,
Rich

Perhaps you could define your own operators for !, !=, ==, ^, ||, &&, +
+, --, etc, but it seems like a pain to me.

Besides why not just do this?
if str != "something" Then

if str <> "something" Then

Seems just as easy as using the C# notation to me.

Thanks,

Seth Rowe
 
I agree that <> is just as easy !=. My issue was just to be more familiar
with VB.Net. So I was just checking if there was any implementation of !.
Like in VBA code you have Me!Text1, RS!fld1, ... so I am just checking if
there was any ! usage in VB.Net. It appears not - which is fine by me. But
I just wanted to make sure I'm not missing out on anything.
 
It's funny how those little things differ between languages. Until yesterday
I was still lamenting the fact that VB didn't have a ternary operator like C
does... testCondition?doIfTrue:doIfFalse;... but then I suddenly came upon
the IIF statement!
 
Peter said:
It's funny how those little things differ between languages. Until yesterday
I was still lamenting the fact that VB didn't have a ternary operator like C
does... testCondition?doIfTrue:doIfFalse;... but then I suddenly came upon
the IIF statement!

Be aware that currently (VB 2005) IIF is just a regular function. This
means that it will evaluate its parameters previous to execution,
which differs from the way the ternary "?:" operator works. For
instance, the assignment bellow will raise an error when executed,
because A(0) is evaluated before IIf is called.

Dim A As List(Of Integer)
Dim B As Integer = IIf(A is Nothing, 0, A(0))

Also, IIF parameters and return type are Object, which takes away most
of its mojo.

Next VB.Net version is supposed to remedy both issues. ;-)

Regards,

Branco.
 
Rich said:
If Not st1.Equals("something") then
Do Something Else
End If

if str1 != "something" Then ...

I realize that != is C# stuff and/or can be also be used in Tsql, but is
there any implementation of bang ! in VB.Net? Just checking. Any samples
appreciated.


Note that C# overloads the '==' and '!=' operators so that they work with
both value types and reference types. Thus it's not obious if value
equality or object identity is compared. Other programming languages, such
as VB, provide different operators for comparing (1) value equality and (2)
object identity.

In VB, the operators '=' and '<>' are used to compare for value equality and
'Is' and 'IsNot' (VB 2005) are used to compare for object identity.
 
Back
Top