473,387 Members | 1,542 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,387 software developers and data experts.

if (var != Undefined.Value) does NOT work

I have a C# program with an if statement similar to

if (obj.myvar != Undefined.Value) { ...... }

When I test it in the CSharp CLR debugger this debugger does not recoginze
that the value is currently <undefined value> as shown in the watch list of the Debugger.
Hence the program branches into the if statement although it should skip it
obviously. Why?

Replacing the if statement above by

if (obj.var != null) { ......}

does NOT help. The programm jumps INTO the if branch.

Steven

Nov 16 '05 #1
5 3384
"Steven Prasil" <pr****@nortel.com> wrote:
if (obj.myvar != Undefined.Value) { ...... }
[...] debugger does not recoginze that the value is
currently <undefined value> [...] Hence the program
branches into the if statement


If the value is undefined, I'd expect it to branch into the if block,
because you're using the != (not equal) operator.

P.
Nov 16 '05 #2
Steven Prasil <pr****@nortel.com> wrote:
I have a C# program with an if statement similar to

if (obj.myvar != Undefined.Value) { ...... }

When I test it in the CSharp CLR debugger this debugger does not recoginze
that the value is currently <undefined value> as shown in the watch list of the Debugger.
Hence the program branches into the if statement although it should skip it
obviously. Why?

Replacing the if statement above by

if (obj.var != null) { ......}

does NOT help. The programm jumps INTO the if branch.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Hi Steven,

Debugger shows <undefined value> whenever reference variable is set to
*null*. For value types it won't show <undefined value>. In other words
*null* is <undefined value> for the debugger.
There is not Undefined.Value class and proerty if this is what you were
trying.

In the first example you posted you test *obj.myvar* in the second
*obj.var*. It might be the reason of the wrong result.

--

HTH
Stoitcho Goutsev (100) [C# MVP]
"Steven Prasil" <pr****@nortel.com> wrote in message
news:cg*************@news.t-online.com...
I have a C# program with an if statement similar to

if (obj.myvar != Undefined.Value) { ...... }

When I test it in the CSharp CLR debugger this debugger does not recoginze
that the value is currently <undefined value> as shown in the watch list of the Debugger. Hence the program branches into the if statement although it should skip it obviously. Why?

Replacing the if statement above by

if (obj.var != null) { ......}

does NOT help. The programm jumps INTO the if branch.

Steven

Nov 16 '05 #4

try if(obj.var == null)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
chandra mohan <sv******@yahoo.com> wrote in message news:<u5**************@tk2msftngp13.phx.gbl>...
try if(obj.var == null)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


When is null != null ?

I have experienced similar problems. The code worked as expected in
non-debug, yet in debug it failed to evaluate correctly.

Try this and see if it helps:

Shutdown Visual Studio.
Delete the contents of your build folders (bin and obj).
Try again.

Andrew Cowan
Devtest Pty Ltd
Nov 16 '05 #6

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

Similar topics

4
by: Karsten | last post by:
Hi I don't get this, could anyone help me out here, thanks :) When I load this page, I always gets the "wrong" alert and password is undefined, but how do I detect this in the code? Checking...
9
by: lkrubner | last post by:
I've got a function, you can see it below, that is being called onmouseup in the textarea on my main form. The idea is to find a selection if possible and store that text in a global variable. I...
6
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and...
1
by: CES | last post by:
All, I have absolutely no clue as to what the difference is between these two snippets but the on that is hard coded works and the other doesn't. I know it's something incredible stupid that I...
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
9
by: Marijn | last post by:
Hey everybody, I was wondering if the following would be a valid JavaScript assignment vor a variable and if anybody knows this to work in IE6 or lower? var someVar = (typeof(someVar) ===...
5
by: ceh | last post by:
Can anyone explain if there is a difference here? I'm lost, Thanks. I have a class that works... function CXMLHTTP() { var xmlhttp; //this.m_xmlhttp; this.url = "";
2
by: kalyke | last post by:
I think the below code should work, but for some reason the setNumbers variable isn't keeping its value after the function. I thought if I declared variables outside of any function they would behave...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.