By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,485 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,485 IT Pros & Developers. It's quick & easy.

How to check if "undefined value" ??

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.