if(myObj == null)
{
        code here ...
}

if(myObj != null)
{
        code here...
}

Richard L Spence,MSCS
RSL Associates Inc.
Software Developer
Specializing in Microsoft ASP.Net
410-788-5558
mailto:[EMAIL PROTECTED]


-----Original Message-----
From: dotnet discussion [mailto:[EMAIL PROTECTED]]On Behalf Of
Urs Eichmann
Sent: Monday, May 06, 2002 2:39 AM
To: [EMAIL PROTECTED]
Subject: [DOTNET] AW: [DOTNET] What is the correct way to test for Is
Nothing in C# ?


VB.NET allowed the syntax

If myObj<>Nothing Then

and

If myObj=Nothing Then

back in Beta.1. They removed this ability in Beta.2, because they feared
that when VB.NET allows operator overloading one day, this syntax might
cause problems. Why this should be a problem for VB.NET but not for C# is
beyond me, but perhaps the VB.NET team *is* more clever than the rest of the
world!

Anyway, there is hope that they'll have a better syntax for the awful "If
Not myObj Is Nothing Then" thing in the next VB.NET version, because lots of
people complained about this in the NGs.

Urs

> Just another reason C# is so much easier to learn than VB. ;-)

PS. Ed, I'm quite fed up with your VB bashing in each and every of your
mails. Could you just stop that? There are enough reasons to prefer VB over
C#, just as there are enough reasons for doing the opposite. Just accept
that, please.


-----Ursprüngliche Nachricht-----
Von: Ed Stegman [mailto:[EMAIL PROTECTED]]
Gesendet: Sonntag, 5. Mai 2002 08:55
An: [EMAIL PROTECTED]
Betreff: Re: [DOTNET] What is the correct way to test for Is Nothing in C#?

Your inclination is correct, and you have nothing to worry about wrt objects
overriding == and tests for null references.

"!= null" and "== null" are syntactic sugar. No methods are invoked on any
object for these particular tests, as you are just
testing whether the address stored in the xyz variable is a 0 or not. (0 ==
null pointer == null reference == Nothing).

I never did understand why the VB designers didn't do the same thing, but
instead came up with the double negative, unintuitive,
"Not someObject Is Nothing" thingy. Not to be confused with the IsNull()
method, or the IsEmpty() method.

Just another reason C# is so much easier to learn than VB. ;-)

Keep Smilin'
Ed Stegman

-----Original Message-----
From: dotnet discussion [mailto:[EMAIL PROTECTED]]On Behalf Of
David Ferguson
Sent: Saturday, May 04, 2002 12:06 PM
To: [EMAIL PROTECTED]
Subject: What is the correct way to test for Is Nothing in C#?


In VB I would say...

    if (Not xyz Is Nothing)

In C# I am inclined to say...

    if (xyz != null)

but I am concerned that an object might override operator !=.  What is the
recommended way to do this test in C#?

Thanks...David

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to