473,587 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3400
"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.co m>
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******* *******@tk2msft ngp13.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
2535
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 if password is "" undefined or "undefined" seems to work. -----------something.asp---------------
9
2220
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 can't get this to work in any browser on a Mac, though it works alright on a PC. What am I missing?
6
10118
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 have the function update the target ID with the URL. There is a bit more to it then that, but that is the basics. my difficulty comes when I try to...
1
1438
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 should know but I just cant see it. //This works if it's hard coded: function setTimer(id,status){ if(status=="start"){ txt = new timer('txt',id);...
35
3562
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 to management theses :-((( I must to declare and use all variable with this scheme :
45
4815
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 "new Array() vs " question or to the array performance, I dared to move it to a new thread. Gecko takes undefined value strictly as per Book 4,...
9
2269
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) === Object) ? this : getVar(); function getVar(){ alert('getVar() called');
5
1855
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
1995
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 globally, so if I put data into them in a function it would carry over out of the function. Where the alert is at the bottom works, but if its moved...
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.