Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

Checking for Session cookies

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 16 Jul 2005 01:15 GMT
I was looking at different ways of doing the same thing and at the moment
was looking at the use of "is" and "=", as I have at times found that I will
do something like

if something = 0

and will get an error that says I can't use "=" (or <>) in this case case I
must use "is" ( or not something is).  I am trying to find out when this is
the case - when I can use the "=" and when I have to use "is.

For example, I have a small piece of code checking for the existance of a
session cookie:

if session("tom") = nothing then
trace.warn("Tom not there")
trace.warn("Len(session('Tom')) = " & Len(session("Tom")))
if len(session("Tom")) = 0 then
 trace.warn("also got a hit on <> 0")
end if
end if

This can also be run as:

if session("tom") is nothing then
trace.warn("Tom not there")
trace.warn("Len(session('Tom')) = " & Len(session("Tom")))
if len(session("Tom")) = 0 then
 trace.warn("also got a hit on <> 0")
end if
end if

So 'session("Tom") = nothing' and 'session("Tom") is nothing' as well as
'Len(session("Tom"))' are all equivalent.

Not sure if there is a best way or just whatever strikes you fancy.

I do know that in some cases you can't use the "=" and  must use "is".  I
just don't know why in some cases you can use both (or all 3 ways) and in
some cases you must us "is".

Can someone help me out on the difference?

Thanks,

Tom
Tom.PesterDELETETHISSS@pandora.be - 16 Jul 2005 02:14 GMT
There are 2 sorts of types if you program in an OO language : reference and
value types

Value types are most built in types like integer, string (I think), money,
etc and you can think of the variable as actualy holding the value.
A reference type is Nothing (null in c#) or contains a reference to the actual
value which is always a class.

If you use  a reference type and you want to know whether it contains a value
you do this by asking " is nothing", ie you are asking if it contains a reference.

But VB.NEt isn't so strict and it allows things like

dim i as integer = 5
if i = nothing then ...

This is not stritly right as i is a value type. But VB.NET guessed what you
ment (but guessing is a bad idea for a compiler).

So to be short : if you are dealing with classes you have to use nothing.

To complicate things further structs are value types. I suggest you google
for "difference reference value type" to dig in deeper cause it's quit a
technical topic.

Let me know if you have any more questions..

Cheers,
Tom Pester

> I was looking at different ways of doing the same thing and at the
> moment was looking at the use of "is" and "=", as I have at times
[quoted text clipped - 40 lines]
>
> Tom
Tom.PesterDELETETHISSS@pandora.be - 16 Jul 2005 02:20 GMT
I found a good text about it :

http://www.awprofessional.com/content/images/0321245660/items/wagner_item6.pdf

Cheers,
Tom Pester

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.