473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

IsNothing vs. Is Nothing

Hi - just a quick question.

I was wondering which is the better "VB.Net" way - to use IsNothing or the
Is Nothing in an If..Then statement

For example:

If IsNothing(myObject) then
'blah blah blah..
End If

vs

If myObject Is Nothing then
'blah blah blah..
End If

Thanks
Steve
Nov 20 '05 #1
12 44858
* "Steve Peterson" <fa******@fakemail.com> scripsit:
I was wondering which is the better "VB.Net" way - to use IsNothing or the
Is Nothing in an If..Then statement

For example:

If IsNothing(myObject) then
'blah blah blah..
End If

vs

If myObject Is Nothing then
'blah blah blah..
End If


Did you have a look at the MSIL code of the compiled executable using
"ildasm.exe"?

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #2
Steve,
I don't believe either is really "better" then the other.

I prefer myObject Is Nothing, however that does not make it "Better".

I would be more concerned with being consistent within the project,
solution, team, company.

Hope this helps
Jay

"Steve Peterson" <fa******@fakemail.com> wrote in message
news:u%****************@TK2MSFTNGP12.phx.gbl...
Hi - just a quick question.

I was wondering which is the better "VB.Net" way - to use IsNothing or the
Is Nothing in an If..Then statement

For example:

If IsNothing(myObject) then
'blah blah blah..
End If

vs

If myObject Is Nothing then
'blah blah blah..
End If

Thanks
Steve

Nov 20 '05 #3
Hi Herfield

Mmm, I guess if I had, or even had a clue what you are talking about, I
probably wouldn't have posted my question in the first place..

If you would be so kind as to decipher your answer a bit, maybe I (and
others) would have some valuable insight for the future on our road to being
better .Net programmers...

Thanks
Steve

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bp*************@ID-208219.news.uni-berlin.de...
Did you have a look at the MSIL code of the compiled executable using
"ildasm.exe"?

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>

Nov 20 '05 #4
* "Steve Peterson" <fa******@fakemail.com> scripsit:
Mmm, I guess if I had, or even had a clue what you are talking about, I
probably wouldn't have posted my question in the first place..

If you would be so kind as to decipher your answer a bit, maybe I (and
others) would have some valuable insight for the future on our road to being
better .Net programmers...


This code

\\\
Dim x As Form
If x Is Nothing Then
Beep()
End If
If IsNothing(x) Then
Beep()
End If
///
compiles to this MSIL:

\\\
IL_0000: nop
IL_0001: ldloc.0
IL_0002: brtrue.s IL_000a
IL_0004: call void [Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0009: nop
IL_000a: nop
IL_000b: ldloc.0
IL_000c: call bool [Microsoft.VisualBasic]Microsoft.VisualBasic.Information::IsNothing(objec t)
IL_0011: brfalse.s IL_0019
IL_0013: call void [Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0018: nop
IL_0019: nop
IL_001a: nop
IL_001b: ret
///

As you can see, the 2nd method requires a call to the 'IsNothing'
object. This may reduce performance.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #5
"Steve Peterson" <fa******@fakemail.com> schrieb
Hi - just a quick question.

I was wondering which is the better "VB.Net" way - to use IsNothing
or the Is Nothing in an If..Then statement

For example:

If IsNothing(myObject) then
'blah blah blah..
End If

vs

If myObject Is Nothing then
'blah blah blah..
End If


I didn't know IsNothing. I use the second version because I don't need a
function for this comparison.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
Thanks for the fish, but I'd like to be a fisherman. =`:^>

How do you run the disassembler to get those answers?
From the command prompt? As a Windows program?

I can launch ildasm.exe as a Windows app, but can't
figure out how to see the IL lines. Would be nice!

-- frosty

Herfried K. Wagner [MVP] wrote:
* "Steve Peterson" <fa******@fakemail.com> scripsit:
Mmm, I guess if I had, or even had a clue what you are talking
about, I probably wouldn't have posted my question in the first
place..

If you would be so kind as to decipher your answer a bit, maybe I
(and others) would have some valuable insight for the future on our
road to being better .Net programmers...
This code

\\\
Dim x As Form
If x Is Nothing Then
Beep()
End If
If IsNothing(x) Then
Beep()
End If
///
compiles to this MSIL:

\\\
IL_0000: nop
IL_0001: ldloc.0
IL_0002: brtrue.s IL_000a
IL_0004: call void
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0009: nop IL_000a: nop
IL_000b: ldloc.0
IL_000c: call bool

[Microsoft.VisualBasic]Microsoft.VisualBasic.Information::IsNothing(objec t)
IL_0011: brfalse.s IL_0019 IL_0013: call void
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0018: nop IL_0019: nop
IL_001a: nop
IL_001b: ret
///

As you can see, the 2nd method requires a call to the 'IsNothing'
object. This may reduce performance.

<http://www.plig.net/nnq/nquote.html>

Nov 20 '05 #7
frostalicious,
Use ildasm.exe.

For VS.NET 2003 it can be found at:
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\ildasm.exe

For VS.NET 2002 it can be found at:
C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin\ildasm.exe

Normally I set up a new "External Tool" in VS.NET to invoke it.

For example in VS.NET 2003 I have:
Title: IL Dasm
Command: C:\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\Bin\ildasm.exe
Arguments: /adv $(TargetPath)
Initial directory: $(TargetDir)

Which will open the assembly for the current project.

Hope this helps
Jay

"frostalicious" <fr*****@nospam.com> wrote in message
news:vr************@corp.supernews.com...
Thanks for the fish, but I'd like to be a fisherman. =`:^>

How do you run the disassembler to get those answers?
From the command prompt? As a Windows program?

I can launch ildasm.exe as a Windows app, but can't
figure out how to see the IL lines. Would be nice!

-- frosty

Herfried K. Wagner [MVP] wrote:
* "Steve Peterson" <fa******@fakemail.com> scripsit:
Mmm, I guess if I had, or even had a clue what you are talking
about, I probably wouldn't have posted my question in the first
place..

If you would be so kind as to decipher your answer a bit, maybe I
(and others) would have some valuable insight for the future on our
road to being better .Net programmers...
This code

\\\
Dim x As Form
If x Is Nothing Then
Beep()
End If
If IsNothing(x) Then
Beep()
End If
///
compiles to this MSIL:

\\\
IL_0000: nop
IL_0001: ldloc.0
IL_0002: brtrue.s IL_000a
IL_0004: call void
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0009: nop IL_000a: nop
IL_000b: ldloc.0
IL_000c: call bool

[Microsoft.VisualBasic]Microsoft.VisualBasic.Information::IsNothing(objec t) IL_0011: brfalse.s IL_0019
IL_0013: call void
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0018: nop IL_0019: nop
IL_001a: nop
IL_001b: ret
///

As you can see, the 2nd method requires a call to the 'IsNothing'
object. This may reduce performance.

<http://www.plig.net/nnq/nquote.html>


Nov 20 '05 #8
In article <vr************@corp.supernews.com>, frostalicious wrote:
Thanks for the fish, but I'd like to be a fisherman. =`:^>

How do you run the disassembler to get those answers?
From the command prompt? As a Windows program?

I can launch ildasm.exe as a Windows app, but can't
figure out how to see the IL lines. Would be nice!

-- frosty

Herfried K. Wagner [MVP] wrote:
* "Steve Peterson" <fa******@fakemail.com> scripsit:
Mmm, I guess if I had, or even had a clue what you are talking
about, I probably wouldn't have posted my question in the first
place..

If you would be so kind as to decipher your answer a bit, maybe I
(and others) would have some valuable insight for the future on our
road to being better .Net programmers...


This code

\\\
Dim x As Form
If x Is Nothing Then
Beep()
End If
If IsNothing(x) Then
Beep()
End If
///
compiles to this MSIL:

\\\
IL_0000: nop
IL_0001: ldloc.0
IL_0002: brtrue.s IL_000a
IL_0004: call void
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0009: nop IL_000a: nop
IL_000b: ldloc.0
IL_000c: call bool

[Microsoft.VisualBasic]Microsoft.VisualBasic.Information::IsNothing(objec t)
IL_0011: brfalse.s IL_0019
IL_0013: call void
[Microsoft.VisualBasic]Microsoft.VisualBasic.Interaction::Beep()
IL_0018: nop IL_0019: nop
IL_001a: nop
IL_001b: ret
///

As you can see, the 2nd method requires a call to the 'IsNothing'
object. This may reduce performance.

<http://www.plig.net/nnq/nquote.html>



Launch ildasm.exe. Go to file->open, navigate to the assembly your
intrested in, double click it. You sill see a list of all the defined
types (assuming you chose a .NET app :), then find the class.member your
interested in and double click it.

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #9
"frostalicious" <fr*****@nospam.com> schrieb
Thanks for the fish, but I'd like to be a fisherman. =`:^>

How do you run the disassembler to get those answers?
From the command prompt? As a Windows program?

I can launch ildasm.exe as a Windows app, but can't
figure out how to see the IL lines. Would be nice!

You can enter ildasm in the help index and will find it's documentation.

But to answer your question: After starting ildasm.exe, open select your Exe
file and you can browse the content and view the IL code.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #10
* "frostalicious" <fr*****@nospam.com> scripsit:
Thanks for the fish, but I'd like to be a fisherman. =`:^>

How do you run the disassembler to get those answers?
From the command prompt? As a Windows program?
From the Visual Studio .NET command prompt. Just start the "ildasm.exe"
tool and open the binary.
I can launch ildasm.exe as a Windows app, but can't
figure out how to see the IL lines. Would be nice!


Just doubleclick a procedure selected from the treeview in the main window.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #11
Cor
Hi Steve,

Reading at Armin answers, I had the same as he and we both have seen a lot
of discussions about "Nothing" in this newsgroup (I have to write "Nothing"
like this from Armin).

But we have also seen a lot of questions/discussions about keywords which
are appearing and disappearing.

If there is no need for a keyword I never would use it. Mostly it gives you
not a very big advantage and the possibility always exist that in a future
release (is it not the next but maybe some after that) that keyword
disappears and you have to change your program anyway.

Just a thought

Cor
Nov 20 '05 #12
Thanks all to your contributions and insights!
Steve
"Steve Peterson" <fa******@fakemail.com> wrote in message
news:u%****************@TK2MSFTNGP12.phx.gbl...
Hi - just a quick question.

I was wondering which is the better "VB.Net" way - to use IsNothing or the
Is Nothing in an If..Then statement

For example:

If IsNothing(myObject) then
'blah blah blah..
End If

vs

If myObject Is Nothing then
'blah blah blah..
End If

Thanks
Steve

Nov 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: BUX | last post by:
They exist in Visual Studio .Net , but I do not know the name of dll to create the reference! Can you please help me?
5
by: Jim Heavey | last post by:
I am trying to transition from VB.Net - what is the equivalent if the IsNothing()? Thanks in advance for your assistance!!!!!!!!!
4
by: tinman | last post by:
Hi.... There appears to be another way of checking if an object IsNothing in ..NET.....was wondering if this approach is better than the classic VB6 way of checking Is Nothing ? Example...
8
by: MattB | last post by:
Hello. I have a vb.net (asp.net) application that uses ado.net datasets. At one point, I need to check a text field in a DataTable to see if there's any text in it before performing text operations...
4
by: Dave Taylor | last post by:
This is really not very important but something that I'm just curious about...which is faster to execute or are they the same: (1) If IsNothing(_myVar) Then ... or (2) If _myVar Is Nothing...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.