Welcome to AddressOf.com Sign in | Help

VB.NET Whidbey Release - The IsNot operator.

Paul Vick explains that there will be a new IsNot operator coming in VB.NET.  Although I don't see a problem with this, I'm not sure having it will make any difference in my development life.  Some of the examples I've seen that point out this new operator are using the following example:

If Not o Is Nothing Then

If the above line was the reason for adding IsNot, I don't think it would be enough to justify the new operator.  The reason for this is that you could write the same thing as:

If IsNothing(o) Then

Hmmm, seems a lot smaller and clearer than either the first example or the following using the new operator.

If o IsNot Nothing Then

Seeing this example thrown around, I wondered why do we need a third way to accomplish the same task?

Well, the new operator actually does a lot more.  First, take the Is operator.  It checkes to see if two variables are the same, not the values, but the actual variables themselves.  Do they share the same reference?  The IsNot does a similar task and checks to see that two variables are not sharing the same reference.  OK, IsNothing() just checks that a variable does not share a reference to Nothing... as does all of the previous examples.  However, what if you want to check the following?

Dim a As New Foo
Dim b As New Bar

If a IsNot b Then

or

If Not a Is b Then

Either way, the two (at least to me) appear to be just as simple to write and read.  Maybe I've just gotten used to using the If Not... format.  However, when translating the following code from C#:

if (a != b)

Where a and b are reference types, the IsNot operator makes for an easier transition between the two languages.

I see the IsNot operator as something that is not necessarily needed, however, it doesn't really hurt anything and if it makes even one developers life easier (while not hurting the rest of the VB.NET community); then I'm one happy camper ;-)

Also, as an added bonus, Paul discusses the history/rational as to why there is the Is operator and why it's not mixed together with the = operator (like some other languages).  I accepted that this was the case with VB.NET and actually kind of hated the fact that I could just use the freakin' equal sign to check if two things were equal (reference types and value types, there just variables right?).  After hearing the rational behind the VB.NET language design decision and the move into Whidbey and operator overloading, having the Is operator is probably going to become my new best friend :-D

Published Tuesday, March 02, 2004 11:59 PM by CorySmith
Filed under:

Comments

# re: VB.NET Whidbey Release - The IsNot operator.

Wednesday, March 10, 2004 1:32 AM by Created by: X
Quote - "Maybe I've just gotten used to using the If Not... format. However, when translating the following code from C#:

if (a != b)

Where a and b are reference types, the IsNot operator makes for an easier transition between the two languages."

It occours to me that the reason for the IsNot operator is to make possible for easier conversion between languages like say from C# to vb.net to some other language.

http://www.kamalpatel.net/ConvertCSharp2VB.aspx

Although the above url works it does have some issues with the c# != operator when converting cirtian code. It would be interesting to see if the documentation for IsNot makes any references to use IsNot if you are planning on having that code translated to and from other languages .... But any way it might just be an attempt to simplify/clean or maybe make the vb.net language more readable in cirtian situations then "if not foobar is nothing then". Sometimes whan I use "If not foo ..." I have to think if that is what I am really intending to do. Where as "If foo IsNot nothing then" seems more logical and natrual to me. I for one probaubly will adopt the IsNot operator.

# re: VB.NET Whidbey Release - The IsNot operator.

Wednesday, March 17, 2004 5:43 AM by Mike Schinkel
I for one am really glad to see it. Writing "Not Is Nothing" is much harder for my feeble brain that "IsNot Nothing."

Maybe that's why I like VB more than C#; I can think in English and still program! :)

# re: VB.NET Whidbey Release - The IsNot operator.

Thursday, September 16, 2004 10:42 AM by Seb Lau
It doesn't seem to work when comparing a datacell to VBNull, e.g.
If dbDT_LOGGEDUSERS.Rows(MACHINEID).Item("USERNAME") IsNot DBNull.Value Then msgbox("logon")

However using the If Not a Is VBNull does seem to work.. [using VS2003]
Anyone else had a similar problem?
Anonymous comments are disabled