[prev in list] [next in list] [prev in thread] [next in thread]
List: mono-devel-list
Subject: Re: [Mono-devel-list] Comparing against null
From: Ben Maurer <bmaurer () ximian ! com>
Date: 2005-04-07 13:57:08
Message-ID: 1112882228.28543.6.camel () linux ! site
[Download RAW message or body]
On Thu, 2005-04-07 at 11:12 +0200, Joe Ante wrote:
> Hi,
>
> Is there a way to compare an object against null with a user defined
> operator?
>
> In mono 1.0.4 i did get operator == called even if comparing against null.
> In mono 1.1.6 that doesn't happen anymore.
> Is this according to the standard? If it is how do i overload comparison
> against null?
Yes, that is correct. On csc x == null *always* does a pointerwise
comparison. I made mcs do this. In some ways it is an optimization (the
user one will at the very least require a function call), in others a
correctness (though that seems very pendantic -- I am not sure if there
are any real life examples where it makes a difference).
If you absolutely need it, have a static readonly variable with the
value of null. However, I'd advise that your equals impl only return
`true' for the equality of null to another null.
-- Ben
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic