How to check for null references
Hans-Eric Grönlund
hasse42g at gmail.com
Mon Aug 27 06:09:14 PDT 2007
Thank you Tim (and the others that pointed this out)! I had a feeling there'd be a simple answer.
Tim Healey Wrote:
> Use 'is' to test for null:
>
> if ( o is null ) { ... }
>
> From http://www.digitalmars.com/d/expression.html#IdentityExpression :
> For class objects, identity is defined as the object references are for
> the same object. Null class objects can be compared with is.
>
> The run-time error you got is because the program was essentially
> executing this:
>
> if ( o.opEquals( null ) ) { ... }
>
> This is intended behavior, though I'm not finding the right spec page to
> link you to at the moment.
More information about the Digitalmars-d
mailing list