472,117 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,117 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 28153
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Don Vaillancourt | last post: by
1 post views Thread by Pavils Jurjans | last post: by
49 posts views Thread by matty | last post: by
9 posts views Thread by Klaus Johannes Rusch | last post: by

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.