469,913 Members | 2,648 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

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 25970
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
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.