[prev in list] [next in list] [prev in thread] [next in thread]
List: mono-devel-list
Subject: [Mono-devel-list] Comparing against null
From: Joe Ante <joe () otee ! dk>
Date: 2005-04-07 9:12:13
Message-ID: BE7AC60D.21EEB%joe () otee ! dk
[Download RAW message or body]
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?
using System;
public class Test
{
static public bool operator == (Test x, Test y)
{
System.Console.WriteLine ("The operator == is being
called");
return false;
}
static public bool operator != (Test x, Test y)
{
System.Console.WriteLine ("The operator != is being
called");
return true;
}
public override bool Equals (object o)
{
System.Console.WriteLine ("Equals function is being
called");
return false;
}
public override int GetHashCode ()
{
System.Console.WriteLine ("Hash function is being called");
return 0;
}
};
public class Bug
{
static void Main(string[] args)
{
Test t = new Test ();
if (t == null)
{
System.Console.WriteLine ("The operator correctly returned
false");
}
else
{
System.Console.WriteLine ("The operator is never called");
}
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic