How to check if "undefined value" ??

  • Thread starter Thread starter Mark Sullivan
  • Start date Start date
M

Mark Sullivan

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
 
Mark Sullivan said:
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 said:
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.
 
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
 
Back
Top