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

How to check if "undefined value" ??

When I trace through a csharp program I came to a situation where a certain values
has an "undefined value" as shown in the debugger DbgClr.

I want to check this but the following statements did not recognize this "non"-value

if (type.Particle != Undefined.Value) { ....

or

if (type.Particle != null) { .....

In each of these code samples above the program went into the if branch instead of skipping it.

Why?

Mark

Nov 16 '05 #1
3 29632
Mark Sullivan <ms***@nortel.com> wrote:
When I trace through a csharp program I came to a situation where a
certain values has an "undefined value" as shown in the debugger
DbgClr.

I want to check this but the following statements did not recognize this "non"-value

if (type.Particle != Undefined.Value) { ....

or

if (type.Particle != null) { .....

In each of these code samples above the program went into the if
branch instead of skipping it.

Why?


The latter should be fine.

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 #2
Jon Skeet [C# MVP] wrote:
Mark Sullivan <ms***@nortel.com> wrote:
When I trace through a csharp program I came to a situation where a
certain values has an "undefined value" as shown in the debugger
DbgClr.

I want to check this but the following statements did not recognize this "non"-value

if (type.Particle != Undefined.Value) { ....

or

if (type.Particle != null) { .....

In each of these code samples above the program went into the if
branch instead of skipping it.

Why?

The latter should be fine.

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.


I'm not sure if i'm understanding your problem right, but the debugger
will highlight something as undefined if your assigning it's value in an
if statement, but if you run a check like that i believe it will find
the value of it when it does parse through the if statements.
Nov 16 '05 #3
Hi Mark,
To check for unassigned values, (which during debug - you will see with
value = <undefined value>) all you need to do is check for null. So if
you want to do something only if 'type.Particle' exists use:
if (type.Particle != null)
{
DoSomething();
}

Best regards,
Joby Joy
Mark Sullivan wrote:
When I trace through a csharp program I came to a situation where a certain values
has an "undefined value" as shown in the debugger DbgClr.

I want to check this but the following statements did not recognize this "non"-value

if (type.Particle != Undefined.Value) { ....

or

if (type.Particle != null) { .....

In each of these code samples above the program went into the if branch instead of skipping it.

Why?

Mark

Nov 16 '05 #4

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

Similar topics

13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
25
by: Nitin Bhardwaj | last post by:
Well, i'm a relatively new into C( strictly speaking : well i'm a student and have been doing & studying C programming for the last 4 years).....and also a regular reader of "comp.lang.c" I...
1
by: Pavils Jurjans | last post by:
Hello, I am building custom hashtable class, and thinking about value retrieval issues. The thing is, that sometimes the hashtable value may contain value null. If someone is reading this value...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
9
by: Klaus Johannes Rusch | last post by:
IE7 returns "unknown" instead of "undefined" when querying the type of an unknown property of an object, for example document.write(typeof window.missingproperty); Has "unknown" been defined...
5
by: Jason | last post by:
Hello, I am trying to dynamically create a table, then set its <td>'s onclick: var table = document.createElement("table"); var row = table.insertRow(-1); var td = row.insertCell(-1);...
5
by: Nathan Sokalski | last post by:
I have an ASP.NET application which is giving the following JavaScript error: 'theForm' is undefined However, when I do a View Source one of the <scriptelements is as follows: <script...
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: 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.